tcparser.pas 289 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305
  1. {
  2. This file is part of the Free Component Library
  3. Copyright (c) 2010-2014 by the Free Pascal development team
  4. SQL source syntax parser test suite
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit tcparser;
  12. {$mode objfpc}{$H+}
  13. interface
  14. uses
  15. Classes, SysUtils, fpcunit, testutils, fpsqltree, fpsqlscanner, fpsqlparser, testregistry;
  16. type
  17. { TTestParser }
  18. TTestParser = Class(TSQLParser)
  19. public
  20. Procedure ParseStringDef(Out DT : TSQLDataType; Out Len : Integer; Out ACharset : TSQLStringtype);
  21. Function ParseType(Flags : TParseTypeFlags) : TSQLTypeDefinition;
  22. Function ParseConstraint : TSQLExpression;
  23. Function ParseProcedureStatements : TSQLStatement;
  24. end;
  25. { TTestSQLParser }
  26. TTestSQLParser = class(TTestCase)
  27. Private
  28. FSource : TStringStream;
  29. FParser : TTestParser;
  30. FToFree : TSQLElement; //will be freed by test teardown
  31. FErrSource : string;
  32. protected
  33. procedure AssertTypeDefaults(TD: TSQLTypeDefinition; Len: Integer=0);
  34. procedure TestStringDef(ASource: String; ExpectDT: TSQLDataType; ExpectLen: Integer; ExpectCharset : TSQLStringType='');
  35. function TestType(ASource : string; AFlags : TParseTypeFlags; AExpectedType : TSQLDataType) : TSQLTypeDefinition;
  36. function TestCheck(ASource : string; AExpectedConstraint : TSQLElementClass) : TSQLExpression;
  37. procedure CreateParser(Const ASource : string);
  38. function CheckClass(E : TSQLElement; C : TSQLElementClass) : TSQLElement;
  39. procedure TestDropStatement(Const ASource : string;C : TSQLElementClass);
  40. function TestCreateStatement(Const ASource,AName : string;C: TSQLElementClass) : TSQLCreateOrAlterStatement;
  41. procedure AssertEquals(const AMessage: String; Expected, Actual: TSQLToken); overload;
  42. procedure AssertEquals(const AMessage: String; Expected, Actual: TSQLBinaryoperation); overload;
  43. procedure AssertEquals(const AMessage: String; Expected, Actual: TSQLUnaryoperation); overload;
  44. procedure AssertEquals(const AMessage: String; Expected, Actual: TSQLternaryoperation); overload;
  45. procedure AssertEquals(const AMessage: String; Expected, Actual: TSQLDataType); overload;
  46. procedure AssertEquals(const AMessage: String; Expected, Actual: TForeignKeyAction); overload;
  47. procedure AssertEquals(const AMessage: String; Expected, Actual: TSQLJoinType); overload;
  48. procedure AssertEquals(const AMessage: String; Expected, Actual: TSQLAggregateFunction); overload;
  49. procedure AssertEquals(const AMessage: String; Expected, Actual: TSQLAggregateOption); overload;
  50. procedure AssertEquals(const AMessage: String; Expected, Actual: TSQLOrderDirection); overload;
  51. procedure AssertEquals(const AMessage: String; Expected, Actual: TPlanJoinType); overload;
  52. procedure AssertEquals(const AMessage: String; Expected, Actual: TTriggerMoment); overload;
  53. procedure AssertEquals(const AMessage: String; Expected, Actual: TTriggerState); overload;
  54. procedure AssertEquals(const AMessage: String; Expected, Actual: TTriggerOperations); overload;
  55. function AssertLiteralExpr(Const AMessage : String; Element : TSQLExpression; ALiteralClass : TSQLElementClass) : TSQLLiteral;
  56. procedure AssertIdentifierName(Const AMessage : String; Const AExpected : String; Element : TSQLElement);
  57. procedure AssertField(AField : TSQLElement; Const AName : String; Const AAlias : String = '');
  58. procedure AssertAggregate(AField : TSQLElement; AAgregate : TSQLAggregateFunction; Const AFieldName : String; AOption : TSQLAggregateOption; Const AAlias : String = '');
  59. procedure AssertAggregateExpression(E : TSQLElement; AAgregate : TSQLAggregateFunction; Const AFieldName : String; AOption : TSQLAggregateOption);
  60. procedure AssertTable(ATable : TSQLElement; Const AName : String; Const AAlias : String = '');
  61. function AssertJoin(AJoin : TSQLElement; Const AFirst,ASecond : String; Const aJoinType : TSQLJoinType) : TSQLJoinTableReference;
  62. function AssertJoinOn(AJoin : TSQLExpression; Const AFirst,ASecond : String; Const AOperation : TSQLBinaryOperation) : TSQLBinaryExpression;
  63. function AssertOrderBy(AOrderBy : TSQLElement; Const AField : String; Const ANumber : Integer; Const AOrdering : TSQLOrderDirection) : TSQLOrderByElement;
  64. function AssertSecondaryFile(ASecondaryFile : TSQLElement; Const AFile : String; Const ALength,AStart : Integer) : TSQLDatabaseFileInfo;
  65. procedure TestTypeError;
  66. procedure TestStringError;
  67. procedure TestCheckError;
  68. procedure TestParseError;
  69. procedure SetUp; override;
  70. procedure TearDown; override;
  71. property Parser : TTestParser Read FParser;
  72. property ToFree : TSQLElement Read FToFree Write FTofree;
  73. end;
  74. { TTestDropParser }
  75. TTestDropParser = Class(TTestSQLParser)
  76. published
  77. procedure TestDropDatabase;
  78. procedure TestDropDomain;
  79. procedure TestDropException;
  80. procedure TestDropGenerator;
  81. procedure TestDropIndex;
  82. procedure TestDropProcedure;
  83. procedure TestDropRole;
  84. procedure TestDropTable;
  85. procedure TestDropTrigger;
  86. procedure TestDropView;
  87. procedure TestDropShadow;
  88. procedure TestDropExternalFunction;
  89. end;
  90. { TTestGeneratorParser }
  91. TTestGeneratorParser = Class(TTestSQLParser)
  92. Published
  93. procedure TestCreateGenerator;
  94. procedure TestSetGenerator;
  95. end;
  96. { TTestRoleParser }
  97. TTestRoleParser = Class(TTestSQLParser)
  98. Published
  99. procedure TestCreateRole;
  100. procedure TestAlterRole;
  101. end;
  102. { TTestTypeParser }
  103. TTestTypeParser = Class(TTestSQLParser)
  104. private
  105. Published
  106. procedure TestStringType1;
  107. procedure TestStringType2;
  108. procedure TestStringType3;
  109. procedure TestStringType4;
  110. procedure TestStringType5;
  111. procedure TestStringType6;
  112. procedure TestStringType7;
  113. procedure TestStringType8;
  114. procedure TestStringType9;
  115. procedure TestStringType10;
  116. procedure TestStringType11;
  117. procedure TestStringType12;
  118. procedure TestStringType13;
  119. procedure TestStringType14;
  120. procedure TestStringType15;
  121. procedure TestStringType16;
  122. procedure TestStringType17;
  123. procedure TestStringType18;
  124. procedure TestStringType19;
  125. procedure TestStringTypeErrors1;
  126. procedure TestStringTypeErrors2;
  127. procedure TestStringTypeErrors3;
  128. procedure TestTypeInt1;
  129. procedure TestTypeInt2;
  130. procedure TestTypeInt3;
  131. procedure TestTypeInt4;
  132. procedure TestTypeInt5;
  133. procedure TestNumerical1;
  134. procedure TestNumerical2;
  135. procedure TestNumerical3;
  136. procedure TestNumericalError1;
  137. procedure TestNumericalError2;
  138. procedure TestNumericalError3;
  139. procedure TestNumericalError4;
  140. procedure TestNumericalError5;
  141. procedure TestNumericalError6;
  142. procedure TestNumericalError7;
  143. procedure TestBlob1;
  144. procedure TestBlob2;
  145. procedure TestBlob3;
  146. procedure TestBlob4;
  147. procedure TestBlob5;
  148. procedure TestBlob6;
  149. procedure TestBlob7;
  150. procedure TestBlob8;
  151. procedure TestBlobError1;
  152. procedure TestBlobError2;
  153. procedure TestBlobError3;
  154. procedure TestBlobError4;
  155. procedure TestBlobError5;
  156. procedure TestBlobError6;
  157. procedure TestBlobError7;
  158. procedure TestSmallInt;
  159. procedure TestFloat;
  160. procedure TestDoublePrecision;
  161. procedure TestDoublePrecisionDefault;
  162. end;
  163. { TTestCheckParser }
  164. TTestCheckParser = Class (TTestSQLParser)
  165. private
  166. published
  167. procedure TestCheckNull;
  168. procedure TestCheckNotNull;
  169. procedure TestCheckBraces;
  170. procedure TestCheckBracesError;
  171. procedure TestCheckParamError;
  172. procedure TestCheckIdentifierError;
  173. procedure TestIsEqual;
  174. procedure TestIsNotEqual1;
  175. procedure TestIsNotEqual2;
  176. procedure TestGreaterThan;
  177. procedure TestGreaterThanEqual1;
  178. procedure TestGreaterThanEqual2;
  179. procedure TestLessThan;
  180. procedure TestLessThanEqual1;
  181. procedure TestLessThanEqual2;
  182. procedure TestLike;
  183. procedure TestNotLike;
  184. procedure TestContaining;
  185. procedure TestNotContaining;
  186. procedure TestStarting;
  187. procedure TestNotStarting;
  188. procedure TestStartingWith;
  189. procedure TestNotStartingWith;
  190. procedure TestBetween;
  191. procedure TestNotBetween;
  192. procedure TestLikeEscape;
  193. procedure TestNotLikeEscape;
  194. procedure TestAnd;
  195. procedure TestOr;
  196. procedure TestNotOr;
  197. end;
  198. { TTestDomainParser }
  199. // Most relevant tests are in type definition testing.
  200. TTestDomainParser = Class(TTestSQLParser)
  201. private
  202. Published
  203. procedure TestSimpleDomain;
  204. procedure TestSimpleDomainAs;
  205. procedure TestNotNullDomain;
  206. procedure TestDefaultNotNullDomain;
  207. procedure TestCheckDomain;
  208. procedure TestDefaultCheckNotNullDomain;
  209. procedure TestAlterDomainDropDefault;
  210. procedure TestAlterDomainDropCheck;
  211. procedure TestAlterDomainDropCheckError;
  212. procedure TestAlterDomainAddCheck;
  213. procedure TestAlterDomainAddConstraintCheck;
  214. procedure TestAlterDomainAddConstraintError;
  215. procedure TestAlterDomainSetDefault;
  216. procedure TestAlterDomainRename;
  217. procedure TestAlterDomainNewType;
  218. procedure TestAlterDomainNewTypeError1;
  219. procedure TestAlterDomainNewTypeError2;
  220. end;
  221. { TTestExceptionParser }
  222. TTestExceptionParser = Class(TTestSQLParser)
  223. Published
  224. procedure TestException;
  225. procedure TestAlterException;
  226. procedure TestExceptionError1;
  227. procedure TestExceptionError2;
  228. end;
  229. { TTestIndexParser }
  230. TTestIndexParser = Class(TTestSQLParser)
  231. private
  232. Published
  233. procedure TestAlterindexActive;
  234. procedure TestAlterindexInactive;
  235. procedure TestCreateIndexSimple;
  236. procedure TestIndexIndexDouble;
  237. procedure TestCreateIndexAscending;
  238. procedure TestCreateIndexDescending;
  239. procedure TestCreateIndexUnique;
  240. procedure TestCreateIndexUniqueAscending;
  241. procedure TestCreateIndexUniqueDescending;
  242. procedure TestIndexError1;
  243. procedure TestIndexError2;
  244. procedure TestIndexError3;
  245. procedure TestIndexError4;
  246. procedure TestIndexError5;
  247. procedure TestIndexError6;
  248. end;
  249. { TTestTableParser }
  250. TTestTableParser = Class(TTestSQLParser)
  251. private
  252. procedure DoTestCreateReferencesField(Const ASource : String; AOnUpdate,AOnDelete : TForeignKeyAction);
  253. Published
  254. procedure TestCreateOneSimpleField;
  255. procedure TestCreateTwoSimpleFields;
  256. procedure TestCreateOnePrimaryField;
  257. procedure TestCreateOneNamedPrimaryField;
  258. procedure TestCreateOneUniqueField;
  259. procedure TestCreateOneNamedUniqueField;
  260. procedure TestCreateNotNullPrimaryField;
  261. procedure TestCreateNotNullDefaultPrimaryField;
  262. procedure TestCreateComputedByField;
  263. procedure TestCreateCheckField;
  264. procedure TestCreateNamedCheckField;
  265. procedure TestCreateReferencesField;
  266. procedure TestCreateReferencesOnUpdateCascadeField;
  267. procedure TestCreateReferencesOnUpdateNoActionField;
  268. procedure TestCreateReferencesOnUpdateSetDefaultField;
  269. procedure TestCreateReferencesOnUpdateSetNullField;
  270. procedure TestCreateReferencesOnDeleteCascadeField;
  271. procedure TestCreateReferencesOnDeleteNoActionField;
  272. procedure TestCreateReferencesOnDeleteSetDefaultField;
  273. procedure TestCreateReferencesOnDeleteSetNullField;
  274. procedure TestCreateReferencesOnUpdateAndDeleteSetNullField;
  275. procedure TestCreateNamedReferencesField;
  276. procedure TestCreatePrimaryKeyConstraint;
  277. procedure TestCreateNamedPrimaryKeyConstraint;
  278. procedure TestCreateForeignKeyConstraint;
  279. procedure TestCreateNamedForeignKeyConstraint;
  280. procedure TestCreateUniqueConstraint;
  281. procedure TestCreateNamedUniqueConstraint;
  282. procedure TestCreateCheckConstraint;
  283. procedure TestCreateNamedCheckConstraint;
  284. procedure TestAlterDropField;
  285. procedure TestAlterDropFields;
  286. procedure TestAlterDropConstraint;
  287. procedure TestAlterDropConstraints;
  288. procedure TestAlterRenameField;
  289. procedure TestAlterRenameColumnField;
  290. procedure TestAlterFieldType;
  291. procedure TestAlterFieldPosition;
  292. procedure TestAlterAddField;
  293. procedure TestAlterAddFields;
  294. procedure TestAlterAddPrimarykey;
  295. procedure TestAlterAddNamedPrimarykey;
  296. procedure TestAlterAddCheckConstraint;
  297. procedure TestAlterAddNamedCheckConstraint;
  298. procedure TestAlterAddForeignkey;
  299. procedure TestAlterAddNamedForeignkey;
  300. end;
  301. { TTestDeleteParser }
  302. TTestDeleteParser = Class(TTestSQLParser)
  303. Private
  304. function TestDelete(Const ASource , ATable: String) : TSQLDeleteStatement;
  305. Published
  306. procedure TestSimpleDelete;
  307. procedure TestSimpleDeleteAlias;
  308. procedure TestDeleteWhereNull;
  309. end;
  310. { TTestUpdateParser }
  311. TTestUpdateParser = Class(TTestSQLParser)
  312. Private
  313. function TestUpdate(Const ASource , ATable: String) : TSQLUpdateStatement;
  314. Published
  315. procedure TestUpdateOneField;
  316. procedure TestUpdateOneFieldFull;
  317. procedure TestUpdateTwoFields;
  318. procedure TestUpdateOneFieldWhereIsNull;
  319. end;
  320. { TTestInsertParser }
  321. TTestInsertParser = Class(TTestSQLParser)
  322. Private
  323. function TestInsert(Const ASource , ATable: String) : TSQLInsertStatement;
  324. Published
  325. procedure TestInsertOneField;
  326. procedure TestInsertTwoFields;
  327. procedure TestInsertOneValue;
  328. procedure TestInsertTwoValues;
  329. end;
  330. { TTestSelectParser }
  331. TTestSelectParser = Class(TTestSQLParser)
  332. Private
  333. FSelect : TSQLSelectStatement;
  334. function TestSelect(Const ASource : String) : TSQLSelectStatement;
  335. procedure TestSelectError(Const ASource : String);
  336. procedure DoExtractSimple(Expected : TSQLExtractElement);
  337. property Select : TSQLSelectStatement Read FSelect;
  338. Published
  339. procedure TestSelectOneFieldOneTable;
  340. procedure TestSelectOneFieldOneTableTransaction;
  341. procedure TestSelectOneArrayFieldOneTable;
  342. procedure TestSelectTwoFieldsOneTable;
  343. procedure TestSelectOneFieldAliasOneTable;
  344. procedure TestSelectTwoFieldAliasesOneTable;
  345. procedure TestSelectOneTableFieldOneTable;
  346. procedure TestSelectOneDistinctFieldOneTable;
  347. procedure TestSelectOneAllFieldOneTable;
  348. procedure TestSelectAsteriskOneTable;
  349. procedure TestSelectDistinctAsteriskOneTable;
  350. procedure TestSelectOneFieldOneTableAlias;
  351. procedure TestSelectOneFieldOneTableAsAlias;
  352. procedure TestSelectTwoFieldsTwoTables;
  353. procedure TestSelectTwoFieldsTwoTablesJoin;
  354. procedure TestSelectTwoFieldsTwoInnerTablesJoin;
  355. procedure TestSelectTwoFieldsTwoLeftTablesJoin;
  356. procedure TestSelectTwoFieldsTwoFullOuterTablesJoin;
  357. procedure TestSelectTwoFieldsTwoFullTablesJoin;
  358. procedure TestSelectTwoFieldsTwoRightTablesJoin;
  359. procedure TestSelectTwoFieldsThreeTablesJoin;
  360. procedure TestSelectTwoFieldsBracketThreeTablesJoin;
  361. procedure TestSelectTwoFieldsThreeBracketTablesJoin;
  362. procedure TestAggregateCount;
  363. procedure TestAggregateCountAsterisk;
  364. procedure TestAggregateCountAll;
  365. procedure TestAggregateCountDistinct;
  366. procedure TestAggregateMax;
  367. procedure TestAggregateMaxAll;
  368. procedure TestAggregateMaxAsterisk;
  369. procedure TestAggregateMaxDistinct;
  370. procedure TestAggregateMin;
  371. procedure TestAggregateMinAll;
  372. procedure TestAggregateMinAsterisk;
  373. procedure TestAggregateMinDistinct;
  374. procedure TestAggregateSum;
  375. procedure TestAggregateSumAll;
  376. procedure TestAggregateSumAsterisk;
  377. procedure TestAggregateSumDistinct;
  378. procedure TestAggregateAvg;
  379. procedure TestAggregateAvgAll;
  380. procedure TestAggregateAvgAsterisk;
  381. procedure TestAggregateAvgDistinct;
  382. procedure TestUpperConst;
  383. procedure TestUpperError;
  384. procedure TestGenID;
  385. procedure TestGenIDError1;
  386. procedure TestGenIDError2;
  387. procedure TestCastSimple;
  388. procedure TestExtractSimple;
  389. procedure TestOrderByOneField;
  390. procedure TestOrderByTwoFields;
  391. procedure TestOrderByThreeFields;
  392. procedure TestOrderByOneDescField;
  393. procedure TestOrderByTwoDescFields;
  394. procedure TestOrderByThreeDescFields;
  395. procedure TestOrderByOneTableField;
  396. procedure TestOrderByOneColumn;
  397. procedure TestOrderByTwoColumns;
  398. procedure TestOrderByTwoColumnsDesc;
  399. procedure TestOrderByCollate;
  400. procedure TestOrderByCollateDesc;
  401. procedure TestOrderByCollateDescTwoFields;
  402. procedure TestGroupByOne;
  403. procedure TestGroupByTwo;
  404. procedure TestHavingOne;
  405. procedure TestUnionSimple;
  406. procedure TestUnionSimpleAll;
  407. procedure TestUnionSimpleOrderBy;
  408. procedure TestUnionDouble;
  409. procedure TestUnionError1;
  410. procedure TestUnionError2;
  411. procedure TestPlanOrderNatural;
  412. procedure TestPlanOrderOrder;
  413. procedure TestPlanOrderIndex1;
  414. procedure TestPlanOrderIndex2;
  415. procedure TestPlanJoinNatural;
  416. procedure TestPlanDefaultNatural;
  417. procedure TestPlanMergeNatural;
  418. procedure TestPlanMergeNested;
  419. procedure TestSubSelect;
  420. procedure TestWhereExists;
  421. procedure TestWhereSingular;
  422. procedure TestWhereAll;
  423. procedure TestWhereAny;
  424. procedure TestWhereSome;
  425. procedure TestParam;
  426. procedure TestParamExpr;
  427. end;
  428. { TTestRollBackParser }
  429. TTestRollBackParser = Class(TTestSQLParser)
  430. Private
  431. FRollback : TSQLRollbackStatement;
  432. function TestRollback(Const ASource : String) : TSQLRollbackStatement;
  433. procedure TestRollbackError(Const ASource : String);
  434. property Rollback : TSQLRollbackStatement Read FRollback;
  435. Published
  436. procedure TestRollback;
  437. procedure TestRollbackWork;
  438. procedure TestRollbackRelease;
  439. procedure TestRollbackWorkRelease;
  440. procedure TestRollbackTransaction;
  441. procedure TestRollbackTransactionWork;
  442. procedure TestRollbackTransactionRelease;
  443. procedure TestRollbackTransactionWorkRelease;
  444. end;
  445. { TTestCommitParser }
  446. TTestCommitParser = Class(TTestSQLParser)
  447. Private
  448. FCommit : TSQLCommitStatement;
  449. function TestCommit(Const ASource : String) : TSQLCommitStatement;
  450. procedure TestCommitError(Const ASource : String);
  451. property Commit : TSQLCommitStatement Read FCommit;
  452. Published
  453. procedure TestCommit;
  454. procedure TestCommitWork;
  455. procedure TestCommitRelease;
  456. procedure TestCommitWorkRelease;
  457. procedure TestCommitTransaction;
  458. procedure TestCommitTransactionWork;
  459. procedure TestCommitTransactionRelease;
  460. procedure TestCommitTransactionWorkRelease;
  461. procedure TestCommitRetain;
  462. procedure TestCommitWorkRetain;
  463. procedure TestCommitReleaseRetain;
  464. procedure TestCommitWorkReleaseRetain;
  465. procedure TestCommitTransactionRetain;
  466. procedure TestCommitTransactionWorkRetain;
  467. procedure TestCommitTransactionReleaseRetain;
  468. procedure TestCommitTransactionWorkReleaseRetain;
  469. procedure TestCommitRetainSnapShot;
  470. end;
  471. { TTestExecuteProcedureParser }
  472. TTestExecuteProcedureParser = Class(TTestSQLParser)
  473. Private
  474. FExecute : TSQLExecuteProcedureStatement;
  475. function TestExecute(Const ASource : String) : TSQLExecuteProcedureStatement;
  476. procedure TestExecuteError(Const ASource : String);
  477. property Execute: TSQLExecuteProcedureStatement Read FExecute;
  478. Published
  479. procedure TestExecuteSimple;
  480. procedure TestExecuteSimpleTransaction;
  481. procedure TestExecuteSimpleReturningValues;
  482. procedure TestExecuteSimpleReturning2Values;
  483. procedure TestExecuteOneArg;
  484. procedure TestExecuteOneArgNB;
  485. procedure TestExecuteTwoArgs;
  486. procedure TestExecuteTwoArgsNB;
  487. procedure TestExecuteOneArgSelect;
  488. procedure TestExecuteOneArgSelectNB;
  489. procedure TestExecuteTwoArgsSelect;
  490. procedure TestExecuteTwoArgsSelectNB;
  491. procedure TestExecuteOneArgSelectErr;
  492. procedure TestExecuteOneArgSelectErr2;
  493. procedure TestExecuteOneArgSelectErr3;
  494. procedure TestExecuteOneArgSelectErr4;
  495. end;
  496. { TTestConnectParser }
  497. TTestConnectParser = Class(TTestSQLParser)
  498. Private
  499. FConnect : TSQLConnectStatement;
  500. function TestConnect(Const ASource : String) : TSQLConnectStatement;
  501. procedure TestConnectError(Const ASource : String);
  502. property Connect: TSQLConnectStatement Read FConnect;
  503. Published
  504. procedure TestConnectSimple;
  505. procedure TestConnectUser;
  506. procedure TestConnectPassword;
  507. procedure TestConnectUserPassword;
  508. procedure TestConnectUserPasswordRole;
  509. procedure TestConnectUserPasswordRoleCache;
  510. procedure TestConnectSimpleCache;
  511. end;
  512. { TTestCreateDatabaseParser }
  513. TTestCreateDatabaseParser = Class(TTestSQLParser)
  514. Private
  515. FCreateDB : TSQLCreateDatabaseStatement;
  516. function TestCreate(Const ASource : String) : TSQLCreateDatabaseStatement;
  517. procedure TestCreateError(Const ASource : String);
  518. property CreateDB : TSQLCreateDatabaseStatement Read FCreateDB;
  519. published
  520. procedure TestSimple;
  521. procedure TestSimpleSchema;
  522. procedure TestSimpleUSer;
  523. procedure TestSimpleUSerPassword;
  524. procedure TestSimplePassword;
  525. procedure TestPageSize;
  526. procedure TestPageSize2;
  527. procedure TestPageSizeLength;
  528. procedure TestPageSizeLength2;
  529. procedure TestPageSizeLength3;
  530. procedure TestPageSizeLength4;
  531. procedure TestCharset;
  532. procedure TestSecondaryFile1;
  533. procedure TestSecondaryFile2;
  534. procedure TestSecondaryFile3;
  535. procedure TestSecondaryFile4;
  536. procedure TestSecondaryFile5;
  537. procedure TestSecondaryFile6;
  538. procedure TestSecondaryFile7;
  539. procedure TestSecondaryFile8;
  540. procedure TestSecondaryFile9;
  541. procedure TestSecondaryFile10;
  542. procedure TestSecondaryFileS;
  543. procedure TestSecondaryFileError1;
  544. procedure TestSecondaryFileError2;
  545. procedure TestSecondaryFileError3;
  546. end;
  547. { TTestAlterDatabaseParser }
  548. TTestAlterDatabaseParser = Class(TTestSQLParser)
  549. Private
  550. FAlterDB : TSQLAlterDatabaseStatement;
  551. function TestAlter(Const ASource : String) : TSQLAlterDatabaseStatement;
  552. procedure TestAlterError(Const ASource : String);
  553. property AlterDB : TSQLAlterDatabaseStatement Read FAlterDB;
  554. published
  555. procedure TestSimple;
  556. procedure TestLength;
  557. procedure TestStarting;
  558. procedure TestStartingLength;
  559. procedure TestFiles;
  560. procedure TestFiles2;
  561. procedure TestError;
  562. procedure TestFilesError;
  563. end;
  564. { TTestCreateViewParser }
  565. TTestCreateViewParser = Class(TTestSQLParser)
  566. Private
  567. FView : TSQLCreateViewStatement;
  568. function TestCreate(Const ASource : String) : TSQLCreateViewStatement;
  569. procedure TestCreateError(Const ASource : String);
  570. property View : TSQLCreateViewStatement Read FView;
  571. Published
  572. procedure TestSimple;
  573. procedure TestFieldList;
  574. procedure TestFieldList2;
  575. procedure TestSimpleWithCheckoption;
  576. end;
  577. { TTestCreateShadowParser }
  578. TTestCreateShadowParser = Class(TTestSQLParser)
  579. Private
  580. FShadow : TSQLCreateShadowStatement;
  581. function TestCreate(Const ASource : String) : TSQLCreateShadowStatement;
  582. procedure TestCreateError(Const ASource : String);
  583. property Shadow : TSQLCreateShadowStatement Read FShadow;
  584. published
  585. procedure TestSimple;
  586. procedure TestLength;
  587. procedure TestLength2;
  588. procedure TestLength3;
  589. procedure TestLength4;
  590. procedure TestSecondaryFile1;
  591. procedure TestSecondaryFile2;
  592. procedure TestSecondaryFile3;
  593. procedure TestSecondaryFile4;
  594. procedure TestSecondaryFile5;
  595. procedure TestSecondaryFile6;
  596. procedure TestSecondaryFile7;
  597. procedure TestSecondaryFile8;
  598. procedure TestSecondaryFileS;
  599. end;
  600. { TTestProcedureStatement }
  601. TTestProcedureStatement = Class(TTestSQLParser)
  602. Private
  603. FStatement : TSQLStatement;
  604. procedure TestParseStatementError;
  605. function TestStatement(Const ASource : String) : TSQLStatement;
  606. procedure TestStatementError(Const ASource : String);
  607. property Statement : TSQLStatement Read FStatement;
  608. Published
  609. procedure TestException;
  610. procedure TestExceptionError;
  611. procedure TestExit;
  612. procedure TestSuspend;
  613. procedure TestEmptyBlock;
  614. procedure TestExitBlock;
  615. procedure TestExitBlockError;
  616. procedure TestPostEvent;
  617. procedure TestPostEventColName;
  618. procedure TestPostError;
  619. procedure TestAssignSimple;
  620. procedure TestAssignSimpleNew;
  621. procedure TestAssignSelect;
  622. procedure TestBlockAssignSimple;
  623. procedure TestIf;
  624. procedure TestIfBlock;
  625. procedure TestIfElse;
  626. procedure TestIfBlockElse;
  627. procedure TestIfElseError;
  628. procedure TestIfBlockElseBlock;
  629. procedure TestIfErrorBracketLeft;
  630. procedure TestIfErrorBracketRight;
  631. procedure TestIfErrorNoThen;
  632. procedure TestIfErrorSemicolonElse;
  633. procedure TestWhile;
  634. procedure TestWhileBlock;
  635. procedure TestWhileErrorBracketLeft;
  636. procedure TestWhileErrorBracketRight;
  637. procedure TestWhileErrorNoDo;
  638. procedure TestWhenAny;
  639. procedure TestWhenSQLCode;
  640. procedure TestWhenGDSCode;
  641. procedure TestWhenException;
  642. procedure TestWhenExceptionGDS;
  643. procedure TestWhenAnyBlock;
  644. procedure TestWhenErrorAny;
  645. procedure TestWhenErrorNoDo;
  646. procedure TestWhenErrorExceptionInt;
  647. procedure TestWhenErrorExceptionString;
  648. procedure TestWhenErrorSqlCode;
  649. procedure TestWhenErrorGDSCode;
  650. procedure TestExecuteStatement;
  651. procedure TestExecuteStatementReturningValues;
  652. procedure TestExecuteStatementReturningValuesColon;
  653. procedure TestExecuteStatementReturningValuesBrackets;
  654. procedure TestForSimple;
  655. procedure TestForSimpleNoColon;
  656. procedure TestForSimple2fields;
  657. procedure TestForBlock;
  658. end;
  659. { TTestCreateProcedureParser }
  660. TTestCreateProcedureParser = Class(TTestSQLParser)
  661. Private
  662. FStatement : TSQLCreateProcedureStatement;
  663. function TestCreate(Const ASource : String) : TSQLCreateProcedureStatement;
  664. procedure TestCreateError(Const ASource : String);
  665. property Statement : TSQLCreateProcedureStatement Read FStatement;
  666. Published
  667. procedure TestEmptyProcedure;
  668. procedure TestExitProcedure;
  669. procedure TestProcedureOneArgument;
  670. procedure TestProcedureTwoArguments;
  671. procedure TestProcedureOneReturnValue;
  672. procedure TestProcedureTwoReturnValues;
  673. procedure TestProcedureOneLocalVariable;
  674. procedure TestProcedureTwoLocalVariable;
  675. procedure TestProcedureInputOutputLocal;
  676. end;
  677. { TTestCreateTriggerParser }
  678. TTestCreateTriggerParser = Class(TTestSQLParser)
  679. Private
  680. FStatement : TSQLAlterCreateTriggerStatement;
  681. function TestCreate(Const ASource : String) : TSQLCreateTriggerStatement;
  682. function TestAlter(Const ASource : String) : TSQLAlterTriggerStatement;
  683. procedure TestCreateError(Const ASource : String);
  684. property Statement : TSQLAlterCreateTriggerStatement Read FStatement;
  685. Published
  686. procedure TestEmptyTrigger;
  687. procedure TestExitTrigger;
  688. procedure TestEmptyTriggerAfterUpdate;
  689. procedure TestEmptyTriggerBeforeDelete;
  690. procedure TestEmptyTriggerBeforeInsert;
  691. procedure TestEmptyTriggerBeforeInsertPosition1;
  692. procedure TestEmptyTriggerBeforeInsertPosition1inActive;
  693. procedure TestEmptyTriggerBeforeInsertPosition1Active;
  694. procedure TestTriggerOneLocalVariable;
  695. procedure TestTriggerTwoLocalVariables;
  696. procedure TestAlterTrigger;
  697. end;
  698. { TTestDeclareExternalFunctionParser }
  699. TTestDeclareExternalFunctionParser = Class(TTestSQLParser)
  700. Private
  701. FStatement : TSQLDeclareExternalFunctionStatement;
  702. function TestCreate(Const ASource : String) : TSQLDeclareExternalFunctionStatement;
  703. procedure TestCreateError(Const ASource : String);
  704. property Statement : TSQLDeclareExternalFunctionStatement Read FStatement;
  705. Published
  706. procedure TestEmptyfunction;
  707. procedure TestEmptyfunctionByValue;
  708. procedure TestCStringfunction;
  709. procedure TestCStringFreeItfunction;
  710. procedure TestOneArgumentFunction;
  711. procedure TestTwoArgumentsFunction;
  712. end;
  713. { TTestGrantParser }
  714. TTestGrantParser = Class(TTestSQLParser)
  715. Private
  716. FStatement : TSQLGrantStatement;
  717. function TestGrant(Const ASource : String) : TSQLGrantStatement;
  718. procedure TestGrantError(Const ASource : String);
  719. property Statement : TSQLGrantStatement Read FStatement;
  720. Published
  721. procedure TestSimple;
  722. procedure Test2Operations;
  723. procedure TestDeletePrivilege;
  724. procedure TestUpdatePrivilege;
  725. procedure TestInsertPrivilege;
  726. procedure TestReferencePrivilege;
  727. procedure TestAllPrivileges;
  728. procedure TestAllPrivileges2;
  729. procedure TestUpdateColPrivilege;
  730. procedure TestUpdate2ColsPrivilege;
  731. procedure TestReferenceColPrivilege;
  732. procedure TestReference2ColsPrivilege;
  733. procedure TestUserPrivilege;
  734. procedure TestUserPrivilegeWithGrant;
  735. procedure TestGroupPrivilege;
  736. procedure TestProcedurePrivilege;
  737. procedure TestViewPrivilege;
  738. procedure TestTriggerPrivilege;
  739. procedure TestPublicPrivilege;
  740. procedure TestExecuteToUser;
  741. procedure TestExecuteToProcedure;
  742. procedure TestRoleToUser;
  743. procedure TestRoleToUserWithAdmin;
  744. procedure TestRoleToPublic;
  745. procedure Test2RolesToUser;
  746. end;
  747. { TTestRevokeParser }
  748. TTestRevokeParser = Class(TTestSQLParser)
  749. Private
  750. FStatement : TSQLRevokeStatement;
  751. function TestRevoke(Const ASource : String) : TSQLRevokeStatement;
  752. procedure TestRevokeError(Const ASource : String);
  753. property Statement : TSQLRevokeStatement Read FStatement;
  754. Published
  755. procedure TestSimple;
  756. procedure Test2Operations;
  757. procedure TestDeletePrivilege;
  758. procedure TestUpdatePrivilege;
  759. procedure TestInsertPrivilege;
  760. procedure TestReferencePrivilege;
  761. procedure TestAllPrivileges;
  762. procedure TestAllPrivileges2;
  763. procedure TestUpdateColPrivilege;
  764. procedure TestUpdate2ColsPrivilege;
  765. procedure TestReferenceColPrivilege;
  766. procedure TestReference2ColsPrivilege;
  767. procedure TestUserPrivilege;
  768. procedure TestUserPrivilegeWithRevoke;
  769. procedure TestGroupPrivilege;
  770. procedure TestProcedurePrivilege;
  771. procedure TestViewPrivilege;
  772. procedure TestTriggerPrivilege;
  773. procedure TestPublicPrivilege;
  774. procedure TestExecuteToUser;
  775. procedure TestExecuteToProcedure;
  776. procedure TestRoleToUser;
  777. procedure TestRoleToPublic;
  778. procedure Test2RolesToUser;
  779. end;
  780. { TTestSetParser }
  781. TTestSetParser = Class(TTestSQLParser)
  782. published
  783. procedure TestSetAutoDDL;
  784. procedure TestSetAutoDDLOn;
  785. procedure TestSetAutoDDLOff;
  786. procedure TestSetAutoDDLCreateProcedure;
  787. procedure TestSetTerm;
  788. procedure TestSetTermSemicolon;
  789. procedure TestSetTermCreateProcedure;
  790. procedure TestSetTermCreateProcedureVar;
  791. end;
  792. { TTestGlobalParser }
  793. TTestGlobalParser = Class(TTestSQLParser)
  794. published
  795. procedure TestEmpty;
  796. end;
  797. implementation
  798. uses typinfo;
  799. { TTestSetParser }
  800. procedure TTestSetParser.TestSetAutoDDL;
  801. begin
  802. CreateParser('SET AUTODDL;');
  803. AssertNull('SET AUTODDL should be ignored and give nil result',Parser.Parse);
  804. end;
  805. procedure TTestSetParser.TestSetAutoDDLOn;
  806. begin
  807. CreateParser('SET AUTODDL ON;');
  808. AssertNull('SET AUTODDL should be ignored and give nil result',Parser.Parse);
  809. end;
  810. procedure TTestSetParser.TestSetAutoDDLOff;
  811. begin
  812. CreateParser('SET AUTODDL OFF;');
  813. AssertNull('SET AUTODDL should be ignored and give nil result',Parser.Parse);
  814. end;
  815. procedure TTestSetParser.TestSetAutoDDLCreateProcedure;
  816. Const
  817. SQL =
  818. 'SET AUTODDL ;'+LineEnding+
  819. ''+LineEnding+
  820. 'CREATE PROCEDURE PROCNAME'+LineEnding+
  821. 'AS'+LineEnding+
  822. 'BEGIN'+LineEnding+
  823. ' /* Empty procedure */'+LineEnding+
  824. 'END;';
  825. begin
  826. CreateParser(SQL);
  827. Parser.ParseScript;
  828. //todo: test name etc of procedure
  829. end;
  830. procedure TTestSetParser.TestSetTerm;
  831. Var
  832. S : TSQLSetTermStatement;
  833. begin
  834. CreateParser('SET TERM ^ ;');
  835. FToFree:=Parser.Parse;
  836. S:=TSQLSetTermStatement(CheckClass(FToFree,TSQLSetTermStatement));
  837. AssertEquals('New value','^',S.NewValue);
  838. AssertEquals('Closing semicolon',tsqlSEMICOLON,Parser.CurrentToken);
  839. Parser.GetNextToken;
  840. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  841. end;
  842. procedure TTestSetParser.TestSetTermSemicolon;
  843. Var
  844. S : TSQLSetTermStatement;
  845. begin
  846. CreateParser('SET TERM ; ^');
  847. FParser.SetStatementTerminator('^'); // emulate a previous SET TERM ^ ;
  848. AssertEquals('Closing statement terminator should match ^','^',Parser.GetStatementTerminator);
  849. FToFree:=Parser.Parse;
  850. S:=TSQLSetTermStatement(CheckClass(FToFree,TSQLSetTermStatement));
  851. AssertEquals('New value',';',S.NewValue);
  852. AssertEquals('Closing terminator',tsqlStatementTerminator,Parser.CurrentToken);
  853. AssertEquals('Closing ^','^',Parser.CurrentTokenString);
  854. Parser.GetNextToken;
  855. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  856. end;
  857. procedure TTestSetParser.TestSetTermCreateProcedure;
  858. Const
  859. SQL =
  860. 'SET TERM ^ ;'+LineEnding+
  861. ''+LineEnding+
  862. 'CREATE PROCEDURE PROCNAME'+LineEnding+
  863. 'AS'+LineEnding+
  864. 'BEGIN'+LineEnding+
  865. ' /* Empty procedure */'+LineEnding+
  866. 'END^'+LineEnding+
  867. ''+LineEnding+
  868. 'SET TERM ; ^';
  869. begin
  870. CreateParser(SQL);
  871. Parser.ParseScript;
  872. //todo: test name etc of procedure
  873. end;
  874. procedure TTestSetParser.TestSetTermCreateProcedureVar;
  875. // Procedure with variable
  876. Const
  877. SQL =
  878. 'SET TERM ^ ;'+LineEnding+
  879. 'CREATE PROCEDURE PROCWITHVAR'+LineEnding+
  880. 'RETURNS (LANGUAGES VARCHAR(15) CHARACTER SET NONE)'+LineEnding+
  881. 'AS'+LineEnding+
  882. 'DECLARE VARIABLE i INTEGER;'+LineEnding+
  883. 'BEGIN'+LineEnding+
  884. ' i = 1;'+LineEnding+
  885. ' WHILE (i <= 5) DO'+LineEnding+
  886. ' BEGIN'+LineEnding+
  887. ' SELECT language_req[:i] FROM job'+LineEnding+
  888. ' INTO :languages;'+LineEnding+
  889. ' i = i +1;'+LineEnding+
  890. ' SUSPEND;'+LineEnding+
  891. ' END'+LineEnding+
  892. 'END ^'+LineEnding+
  893. 'SET TERM ; ^';
  894. begin
  895. CreateParser(SQL);
  896. Parser.ParseScript;
  897. //todo: test name etc of procedure
  898. end;
  899. { TTestGlobalParser }
  900. procedure TTestGlobalParser.TestEmpty;
  901. begin
  902. CreateParser('');
  903. AssertNull('Empty statement returns nil',Parser.Parse);
  904. end;
  905. { --------------------------------------------------------------------
  906. TTestParser
  907. --------------------------------------------------------------------}
  908. procedure TTestParser.ParseStringDef(Out DT: TSQLDataType; Out Len: Integer; Out ACharset : TSQLStringtype);
  909. begin
  910. ParseCharTypeDefinition(DT,Len,ACharset);
  911. end;
  912. function TTestParser.ParseType(Flags: TParseTypeFlags): TSQLTypeDefinition;
  913. begin
  914. Result:=ParseTypeDefinition(Nil,Flags);
  915. end;
  916. function TTestParser.ParseConstraint: TSQLExpression;
  917. begin
  918. // GetNextToken;
  919. Result:=ParseCheckConstraint(Nil);
  920. end;
  921. function TTestParser.ParseProcedureStatements: TSQLStatement;
  922. begin
  923. Result:=Self.ParseProcedureStatement(Nil);
  924. end;
  925. { --------------------------------------------------------------------
  926. TTestSQLParser
  927. --------------------------------------------------------------------}
  928. procedure TTestSQLParser.SetUp;
  929. begin
  930. FParser.SetStatementTerminator(';');
  931. end;
  932. procedure TTestSQLParser.TearDown;
  933. begin
  934. FreeAndNil(FParser);
  935. FreeAndNil(FSource);
  936. FreeAndNil(FToFree);
  937. end;
  938. procedure TTestSQLParser.CreateParser(const ASource: string);
  939. begin
  940. FSource:=TStringStream.Create(ASource);
  941. FParser:=TTestParser.Create(FSource);
  942. end;
  943. Function TTestSQLParser.CheckClass(E: TSQLElement; C: TSQLElementClass) : TSQLElement;
  944. begin
  945. AssertEquals(C,E.ClassType);
  946. Result:=E;
  947. end;
  948. procedure TTestSQLParser.AssertEquals(const AMessage: String; Expected, Actual: TSQLToken);
  949. Var
  950. NE,NA : String;
  951. begin
  952. NE:=GetEnumName(TypeInfo(TSQLToken),Ord(Expected));
  953. NA:=GetEnumName(TypeInfo(TSQLToken),Ord(Actual));
  954. AssertEquals(AMessage,NE,NA);
  955. end;
  956. procedure TTestSQLParser.AssertEquals(const AMessage: String; Expected,
  957. Actual: TSQLBinaryOperation);
  958. Var
  959. NE,NA : String;
  960. begin
  961. NE:=GetEnumName(TypeInfo(TSQLBinaryOperation),Ord(Expected));
  962. NA:=GetEnumName(TypeInfo(TSQLBinaryOperation),Ord(Actual));
  963. AssertEquals(AMessage,NE,NA);
  964. end;
  965. procedure TTestSQLParser.AssertEquals(const AMessage: String; Expected,
  966. Actual: TSQLUnaryoperation);
  967. Var
  968. NE,NA : String;
  969. begin
  970. NE:=GetEnumName(TypeInfo(TSQLUnaryOperation),Ord(Expected));
  971. NA:=GetEnumName(TypeInfo(TSQLUnaryOperation),Ord(Actual));
  972. AssertEquals(AMessage,NE,NA);
  973. end;
  974. procedure TTestSQLParser.AssertEquals(const AMessage: String; Expected,
  975. Actual: TSQLternaryoperation);
  976. Var
  977. NE,NA : String;
  978. begin
  979. NE:=GetEnumName(TypeInfo(TSQLTernaryOperation),Ord(Expected));
  980. NA:=GetEnumName(TypeInfo(TSQLTernaryOperation),Ord(Actual));
  981. AssertEquals(AMessage,NE,NA);
  982. end;
  983. procedure TTestSQLParser.AssertEquals(const AMessage: String; Expected, Actual: TSQLDataType);
  984. Var
  985. NE,NA : String;
  986. begin
  987. NE:=GetEnumName(TypeInfo(TSQLDataType),Ord(Expected));
  988. NA:=GetEnumName(TypeInfo(TSQLDataType),Ord(Actual));
  989. AssertEquals(AMessage,NE,NA);
  990. end;
  991. procedure TTestSQLParser.AssertEquals(const AMessage: String; Expected,
  992. Actual: TForeignKeyAction);
  993. Var
  994. NE,NA : String;
  995. begin
  996. NE:=GetEnumName(TypeInfo(TForeignKeyAction),Ord(Expected));
  997. NA:=GetEnumName(TypeInfo(TForeignKeyAction),Ord(Actual));
  998. AssertEquals(AMessage,NE,NA);
  999. end;
  1000. procedure TTestSQLParser.AssertEquals(const AMessage: String; Expected,
  1001. Actual: TSQLJoinType);
  1002. Var
  1003. NE,NA : String;
  1004. begin
  1005. NE:=GetEnumName(TypeInfo(TSQLJoinType),Ord(Expected));
  1006. NA:=GetEnumName(TypeInfo(TSQLJoinType),Ord(Actual));
  1007. AssertEquals(AMessage,NE,NA);
  1008. end;
  1009. procedure TTestSQLParser.AssertEquals(const AMessage: String; Expected,
  1010. Actual: TSQLAggregateFunction);
  1011. Var
  1012. NE,NA : String;
  1013. begin
  1014. NE:=GetEnumName(TypeInfo(TSQLAggregateFunction),Ord(Expected));
  1015. NA:=GetEnumName(TypeInfo(TSQLAggregateFunction),Ord(Actual));
  1016. AssertEquals(AMessage,NE,NA);
  1017. end;
  1018. procedure TTestSQLParser.AssertEquals(const AMessage: String; Expected,
  1019. Actual: TSQLAggregateOption);
  1020. Var
  1021. NE,NA : String;
  1022. begin
  1023. NE:=GetEnumName(TypeInfo(TSQLAggregateOption),Ord(Expected));
  1024. NA:=GetEnumName(TypeInfo(TSQLAggregateOption),Ord(Actual));
  1025. AssertEquals(AMessage,NE,NA);
  1026. end;
  1027. procedure TTestSQLParser.AssertEquals(const AMessage: String; Expected,
  1028. Actual: TSQLOrderDirection);
  1029. Var
  1030. NE,NA : String;
  1031. begin
  1032. NE:=GetEnumName(TypeInfo(TSQLOrderDirection),Ord(Expected));
  1033. NA:=GetEnumName(TypeInfo(TSQLOrderDirection),Ord(Actual));
  1034. AssertEquals(AMessage,NE,NA);
  1035. end;
  1036. procedure TTestSQLParser.AssertEquals(const AMessage: String; Expected,
  1037. Actual: TPlanJoinType);
  1038. Var
  1039. NE,NA : String;
  1040. begin
  1041. NE:=GetEnumName(TypeInfo(TPlanJoinType),Ord(Expected));
  1042. NA:=GetEnumName(TypeInfo(TPlanJoinType),Ord(Actual));
  1043. AssertEquals(AMessage,NE,NA);
  1044. end;
  1045. procedure TTestSQLParser.AssertEquals(const AMessage: String; Expected,
  1046. Actual: TTriggerMoment);
  1047. Var
  1048. NE,NA : String;
  1049. begin
  1050. NE:=GetEnumName(TypeInfo(TTriggerMoment),Ord(Expected));
  1051. NA:=GetEnumName(TypeInfo(TTriggerMoment),Ord(Actual));
  1052. AssertEquals(AMessage,NE,NA);
  1053. end;
  1054. procedure TTestSQLParser.AssertEquals(const AMessage: String; Expected,
  1055. Actual: TTriggerState);
  1056. Var
  1057. NE,NA : String;
  1058. begin
  1059. NE:=GetEnumName(TypeInfo(TTriggerState),Ord(Expected));
  1060. NA:=GetEnumName(TypeInfo(TTriggerState),Ord(Actual));
  1061. AssertEquals(AMessage,NE,NA);
  1062. end;
  1063. procedure TTestSQLParser.AssertEquals(const AMessage: String; Expected,
  1064. Actual: TTriggerOperations);
  1065. Var
  1066. NE,NA : String;
  1067. begin
  1068. If Expected<>Actual then
  1069. Fail(Amessage)
  1070. end;
  1071. Function TTestSQLParser.AssertLiteralExpr(const AMessage: String;
  1072. Element: TSQLExpression; ALiteralClass: TSQLElementClass) : TSQLLiteral;
  1073. begin
  1074. CheckClass(Element,TSQLLiteralExpression);
  1075. Result:=TSQLLiteral(Checkclass(TSQLLiteralExpression(Element).Literal,ALiteralClass));
  1076. end;
  1077. procedure TTestSQLParser.AssertIdentifierName(const AMessage : String;
  1078. const AExpected: String; Element: TSQLElement);
  1079. begin
  1080. AssertNotNull(AMessage+': Have identifier ',Element);
  1081. CheckClass(Element,TSQLidentifierName);
  1082. AssertEquals(AMessage+': Correct identifier name',AExpected,TSQLidentifierName(Element).Name);
  1083. end;
  1084. procedure TTestSQLParser.AssertField(AField: TSQLElement; const AName: String;
  1085. const AAlias: String);
  1086. Var
  1087. F : TSQLSelectField;
  1088. E : TSQLidentifierExpression;
  1089. begin
  1090. AssertNotNull('Have field',AField);
  1091. F:=TSQLSelectField(CheckClass(AField,TSQLSelectField));
  1092. AssertNotNull('Have field expresssion,',F.Expression);
  1093. E:=TSQLidentifierExpression(CheckClass(F.Expression,TSQLidentifierExpression));
  1094. AssertIdentifierName('Correct field name',AName,E.Identifier);
  1095. If (AAlias<>'') then
  1096. AssertIdentifierName('Correct alias',AALias,F.AliasName);
  1097. end;
  1098. procedure TTestSQLParser.AssertAggregate(AField: TSQLElement;
  1099. AAgregate: TSQLAggregateFunction; const AFieldName: String;
  1100. AOption: TSQLAggregateOption; const AAlias: String);
  1101. Var
  1102. F : TSQLSelectField;
  1103. begin
  1104. AssertNotNull('Have field',AField);
  1105. F:=TSQLSelectField(CheckClass(AField,TSQLSelectField));
  1106. AssertNotNull('Have field expresssion,',F.Expression);
  1107. AssertAggregateExpression(F.Expression,AAgregate,AFieldName,AOption);
  1108. If (AAlias<>'') then
  1109. AssertIdentifierName('Correct alias',AALias,F.AliasName);
  1110. end;
  1111. procedure TTestSQLParser.AssertAggregateExpression(E: TSQLElement;
  1112. AAgregate: TSQLAggregateFunction; const AFieldName: String;
  1113. AOption: TSQLAggregateOption);
  1114. Var
  1115. AF : TSQLAggregateFunctionExpression;
  1116. I : TSQLIdentifierExpression;
  1117. begin
  1118. AF:=TSQLAggregateFunctionExpression(CheckClass(E,TSQLAggregateFunctionExpression));
  1119. AssertEquals('Correct function',AAgregate,AF.Aggregate);
  1120. AssertEquals('Correct function',AOption,AF.Option);
  1121. If (AFieldName<>'') then
  1122. begin
  1123. I:=TSQLIdentifierExpression(CheckClass(AF.Expression, TSQLIdentifierExpression));
  1124. AssertIdentifierName('Correct field name',AFieldName,I.Identifier);
  1125. end;
  1126. end;
  1127. procedure TTestSQLParser.AssertTable(ATable: TSQLElement; const AName: String;
  1128. const AAlias: String);
  1129. Var
  1130. T : TSQLSimpleTablereference;
  1131. begin
  1132. AssertNotNull('Have table',ATable);
  1133. T:=TSQLSimpleTablereference(CheckClass(ATable,TSQLSimpleTablereference));
  1134. AssertIdentifierName('Correct table name',AName,T.ObjectName);
  1135. If (AAlias<>'') then
  1136. AssertIdentifierName('Correct alias',AALias,T.AliasName);
  1137. end;
  1138. function TTestSQLParser.AssertJoin(AJoin: TSQLElement; const AFirst,
  1139. ASecond: String; const ajointype: TSQLJoinType):TSQLJoinTableReference;
  1140. Var
  1141. J : TSQLJoinTableReference;
  1142. begin
  1143. AssertNotNull('Have join',AJoin);
  1144. J:=TSQLJoinTableReference(CheckClass(AJoin,TSQLJoinTableReference));
  1145. if (AFirst<>'') then
  1146. AssertTable(J.Left,AFirst,'');
  1147. if (ASecond<>'') then
  1148. AssertTable(J.Right,ASecond,'');
  1149. AssertEquals('Correct join type',AJoinType,J.JoinType);
  1150. Result:=J;
  1151. end;
  1152. function TTestSQLParser.AssertJoinOn(AJoin: TSQLExpression; const AFirst,
  1153. ASecond: String; const AOperation: TSQLBinaryOperation): TSQLBinaryExpression;
  1154. Var
  1155. I : TSQLIdentifierExpression;
  1156. begin
  1157. Result:=TSQLBinaryExpression(CheckClass(AJoin,TSQLBinaryExpression));
  1158. AssertEquals('Correct ON operation',AOperation,Result.Operation);
  1159. I:=TSQLIdentifierExpression(CheckClass(Result.Left,TSQLIdentifierExpression));
  1160. AssertIdentifierName('Left field name',AFirst,I.Identifier);
  1161. I:=TSQLIdentifierExpression(CheckClass(Result.Right,TSQLIdentifierExpression));
  1162. AssertIdentifierName('Right field name',ASecond,I.Identifier);
  1163. end;
  1164. function TTestSQLParser.AssertOrderBy(AOrderBy: TSQLElement;
  1165. const AField: String; const ANumber: Integer; const AOrdering: TSQLOrderDirection
  1166. ): TSQLOrderByElement;
  1167. Var
  1168. I : TSQLIntegerLiteral;
  1169. begin
  1170. Result:=TSQLOrderByElement(CheckClass(AorderBy,TSQLOrderByElement));
  1171. If (AField<>'') then
  1172. AssertIdentifierName('Correct order by field',AField,Result.Field)
  1173. else if (ANumber>0) then
  1174. begin
  1175. I:=TSQLIntegerLiteral(CheckClass(Result.Field,TSQLIntegerLiteral));
  1176. AssertEquals('Correct order by column number',ANumber,I.Value);
  1177. end;
  1178. AssertEquals('Correct ordering',AOrdering,Result.OrderBy);
  1179. end;
  1180. function TTestSQLParser.AssertSecondaryFile(ASecondaryFile: TSQLElement;
  1181. const AFile: String; const ALength, AStart: Integer): TSQLDatabaseFileInfo;
  1182. begin
  1183. Result:=TSQLDatabaseFileInfo(CheckClass(ASecondaryFile,TSQLDatabaseFileInfo));
  1184. AssertEquals('Secondary file name',AFile,Result.FileName);
  1185. AssertEquals('Secondary file length',ALength,Result.Length);
  1186. AssertEquals('Secondary file start',AStart,Result.StartPage);
  1187. end;
  1188. procedure TTestSQLParser.TestTypeError;
  1189. begin
  1190. TestType(FErrSource,[],sdtInteger);
  1191. end;
  1192. procedure TTestSQLParser.TestStringError;
  1193. begin
  1194. TestStringDef(FErrSource,sdtchar,0);
  1195. end;
  1196. procedure TTestSQLParser.TestCheckError;
  1197. begin
  1198. TestCheck(FErrSource,TSQLExpression);
  1199. end;
  1200. procedure TTestSQLParser.TestParseError;
  1201. begin
  1202. CreateParser(FErrSource);
  1203. FToFree:=Parser.Parse;
  1204. end;
  1205. procedure TTestSQLParser.TestStringDef(ASource : String; ExpectDT : TSQLDataType; ExpectLen : Integer; ExpectCharset : TSQLStringType='');
  1206. Var
  1207. Dt : TSQLDataType;
  1208. L : integer;
  1209. cs : TSQLStringType;
  1210. begin
  1211. CreateParser(ASOURCE);
  1212. Parser.GetNextToken;
  1213. Parser.ParseStringDef(dt,l,cs);
  1214. AssertEquals('Datatype is CHAR',ExpectDT,Dt);
  1215. AssertEquals('Length is 1',ExpectLen,l);
  1216. AssertEquals('End of Stream reached',tsqlEOF,Parser.CurrentToken);
  1217. AssertEquals('Correct character set',ExpectCharset,CS);
  1218. end;
  1219. Function TTestSQLParser.TestType(ASource : string; AFlags : TParseTypeFlags; AExpectedType : TSQLDataType) : TSQLTypeDefinition;
  1220. begin
  1221. CreateParser(ASource);
  1222. FToFree:=Parser.ParseType(AFlags);
  1223. AssertNotNull('ParseType returns result',FToFree);
  1224. CheckClass(FTofree,TSQLTypeDefinition);
  1225. Result:=TSQLTypeDefinition(FToFree);
  1226. AssertEquals('Type definition has correct data type',AExpectedType,Result.Datatype);
  1227. end;
  1228. function TTestSQLParser.TestCheck(ASource: string; AExpectedConstraint: TSQLElementClass
  1229. ): TSQLExpression;
  1230. begin
  1231. CreateParser('('+ASource+')');
  1232. FToFree:=Parser.ParseConstraint();
  1233. AssertNotNull('ParseType returns result',FToFree);
  1234. CheckClass(FTofree,AExpectedConstraint);
  1235. Result:=TSQLExpression(FToFree);
  1236. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  1237. end;
  1238. procedure TTestSQLParser.AssertTypeDefaults(TD : TSQLTypeDefinition;Len : Integer = 0);
  1239. begin
  1240. AssertNull(TD.DefaultValue);
  1241. AssertNull(TD.Check);
  1242. AssertNull(TD.Collation);
  1243. AssertEquals('Array dim 0',0,TD.ArrayDim);
  1244. AssertEquals('Blob type 0',0,TD.BlobType);
  1245. AssertEquals('Not required',False,TD.NotNull);
  1246. AssertEquals('Length',Len,TD.Len);
  1247. end;
  1248. procedure TTestSQLParser.TestDropStatement(const ASource: string;
  1249. C: TSQLElementClass);
  1250. Var
  1251. D : TSQLDropStatement;
  1252. begin
  1253. If ASOURCE='SHADOW' then
  1254. CreateParser('DROP '+ASource+' 1')
  1255. else
  1256. CreateParser('DROP '+ASource+' A');
  1257. FToFree:=Parser.Parse;
  1258. AssertNotNull('Parse returns result',FTofree);
  1259. If Not FToFree.InheritsFrom(TSQLDropStatement) then
  1260. Fail('Drop statement is not of type TSQLDropStatement');
  1261. CheckClass(FToFree ,C);
  1262. D:=TSQLDropStatement(FToFree);
  1263. If ASOURCE='SHADOW' then
  1264. AssertIdentifierName('object name','1',D.ObjectName)
  1265. else
  1266. AssertIdentifierName('object name','A',D.ObjectName);
  1267. end;
  1268. function TTestSQLParser.TestCreateStatement(const ASource,AName: string;
  1269. C: TSQLElementClass): TSQLCreateOrAlterStatement;
  1270. begin
  1271. CreateParser(ASource);
  1272. FToFree:=Parser.Parse;
  1273. AssertNotNull('Parse returns result',FTofree);
  1274. If Not FToFree.InheritsFrom(TSQLCreateOrAlterStatement) then
  1275. Fail('create statement is not of type TSQLCreateOrAlterStatement');
  1276. CheckClass(FToFree ,C);
  1277. Result:=TSQLCreateOrAlterStatement(FToFree);
  1278. AssertIdentifierName('Correct identifier',AName,Result.ObjectName);
  1279. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  1280. end;
  1281. { --------------------------------------------------------------------
  1282. TTestDropParser
  1283. --------------------------------------------------------------------}
  1284. procedure TTestDropParser.TestDropDatabase;
  1285. begin
  1286. TestDropStatement('DATABASE',TSQLDropDatabaseStatement);
  1287. end;
  1288. procedure TTestDropParser.TestDropDomain;
  1289. begin
  1290. TestDropStatement('DOMAIN',TSQLDropDomainStatement);
  1291. end;
  1292. procedure TTestDropParser.TestDropException;
  1293. begin
  1294. TestDropStatement('EXCEPTION',TSQLDropExceptionStatement);
  1295. end;
  1296. procedure TTestDropParser.TestDropGenerator;
  1297. begin
  1298. TestDropStatement('GENERATOR',TSQLDropGeneratorStatement);
  1299. end;
  1300. procedure TTestDropParser.TestDropIndex;
  1301. begin
  1302. TestDropStatement('INDEX',TSQLDropIndexStatement);
  1303. end;
  1304. procedure TTestDropParser.TestDropProcedure;
  1305. begin
  1306. TestDropStatement('PROCEDURE',TSQLDropProcedureStatement);
  1307. end;
  1308. procedure TTestDropParser.TestDropRole;
  1309. begin
  1310. TestDropStatement('ROLE',TSQLDropRoleStatement);
  1311. end;
  1312. procedure TTestDropParser.TestDropTable;
  1313. begin
  1314. TestDropStatement('TABLE',TSQLDropTableStatement);
  1315. end;
  1316. procedure TTestDropParser.TestDropTrigger;
  1317. begin
  1318. TestDropStatement('TRIGGER',TSQLDropTriggerStatement);
  1319. end;
  1320. procedure TTestDropParser.TestDropView;
  1321. begin
  1322. TestDropStatement('VIEW',TSQLDropViewStatement);
  1323. end;
  1324. procedure TTestDropParser.TestDropShadow;
  1325. begin
  1326. TestDropStatement('SHADOW',TSQLDropShadowStatement);
  1327. end;
  1328. procedure TTestDropParser.TestDropExternalFunction;
  1329. begin
  1330. TestDropStatement('EXTERNAL FUNCTION',TSQLDropExternalFunctionStatement);
  1331. end;
  1332. { --------------------------------------------------------------------
  1333. TTestGeneratorParser
  1334. --------------------------------------------------------------------}
  1335. procedure TTestGeneratorParser.TestCreateGenerator;
  1336. begin
  1337. TestCreateStatement('CREATE GENERATOR A','A',TSQLCreateGeneratorStatement);
  1338. end;
  1339. procedure TTestGeneratorParser.TestSetGenerator;
  1340. Var
  1341. S : TSQLSetGeneratorStatement;
  1342. begin
  1343. CreateParser('SET GENERATOR A TO 1');
  1344. FToFree:=Parser.Parse;
  1345. S:=TSQLSetGeneratorStatement(CheckClass(FToFree,TSQLSetGeneratorStatement));
  1346. AssertIdentifierName('Correct generator name','A',S.Objectname);
  1347. AssertEquals('New value',1,S.NewValue);
  1348. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  1349. end;
  1350. { --------------------------------------------------------------------
  1351. TTestTypeParser
  1352. --------------------------------------------------------------------}
  1353. procedure TTestTypeParser.TestStringType1;
  1354. begin
  1355. TestStringDef('CHAR(1)',sdtChar,1);
  1356. end;
  1357. procedure TTestTypeParser.TestStringType2;
  1358. begin
  1359. TestStringDef('CHAR',sdtChar,0);
  1360. end;
  1361. procedure TTestTypeParser.TestStringType3;
  1362. begin
  1363. TestStringDef('CHARACTER',sdtChar,0);
  1364. end;
  1365. procedure TTestTypeParser.TestStringType4;
  1366. begin
  1367. TestStringDef('CHARACTER VARYING',sdtVarChar,0);
  1368. end;
  1369. procedure TTestTypeParser.TestStringType5;
  1370. begin
  1371. TestStringDef('VARCHAR',sdtVarChar,0);
  1372. end;
  1373. procedure TTestTypeParser.TestStringType6;
  1374. begin
  1375. TestStringDef('VARCHAR(2)',sdtVarChar,2);
  1376. end;
  1377. procedure TTestTypeParser.TestStringType7;
  1378. begin
  1379. TestStringDef('CHARACTER VARYING (2)',sdtVarChar,2);
  1380. end;
  1381. procedure TTestTypeParser.TestStringType8;
  1382. begin
  1383. TestStringDef('NATIONAL CHARACTER VARYING (2)',sdtNVarChar,2);
  1384. end;
  1385. procedure TTestTypeParser.TestStringType9;
  1386. begin
  1387. TestStringDef('NATIONAL CHARACTER (2)',sdtNChar,2);
  1388. end;
  1389. procedure TTestTypeParser.TestStringType10;
  1390. begin
  1391. TestStringDef('NATIONAL CHARACTER',sdtNChar,0);
  1392. end;
  1393. procedure TTestTypeParser.TestStringType11;
  1394. begin
  1395. TestStringDef('NATIONAL CHARACTER VARYING',sdtNVarChar,0);
  1396. end;
  1397. procedure TTestTypeParser.TestStringType12;
  1398. begin
  1399. TestStringDef('NCHAR',sdtNChar,0);
  1400. end;
  1401. procedure TTestTypeParser.TestStringType13;
  1402. begin
  1403. TestStringDef('NCHAR(2)',sdtNChar,2);
  1404. end;
  1405. procedure TTestTypeParser.TestStringType14;
  1406. begin
  1407. TestStringDef('NCHAR VARYING(2)',sdtNVarChar,2);
  1408. end;
  1409. procedure TTestTypeParser.TestStringType15;
  1410. begin
  1411. TestStringDef('CHAR (15) CHARACTER SET UTF8',sdtChar,15,'UTF8');
  1412. end;
  1413. procedure TTestTypeParser.TestStringType16;
  1414. begin
  1415. TestStringDef('CHAR VARYING (15) CHARACTER SET UTF8',sdtVarChar,15,'UTF8');
  1416. end;
  1417. procedure TTestTypeParser.TestStringType17;
  1418. begin
  1419. TestStringDef('CHAR VARYING CHARACTER SET UTF8',sdtVarChar,0,'UTF8');
  1420. end;
  1421. procedure TTestTypeParser.TestStringType18;
  1422. begin
  1423. TestStringDef('CHARACTER CHARACTER SET UTF8',sdtChar,0,'UTF8');
  1424. end;
  1425. procedure TTestTypeParser.TestStringType19;
  1426. Var
  1427. T : TSQLTypeDefinition;
  1428. begin
  1429. T:=TestType('CHAR(10) COLLATE UTF8',[],sdtChar);
  1430. AssertNotNull('Have collation',T.Collation);
  1431. AssertEquals('Correct collation','UTF8',T.Collation.Name);
  1432. end;
  1433. procedure TTestTypeParser.TestStringTypeErrors1;
  1434. begin
  1435. FErrSource:='VARCHAR VARYING';
  1436. AssertException(ESQLParser,@TestStringError);
  1437. end;
  1438. procedure TTestTypeParser.TestStringTypeErrors2;
  1439. begin
  1440. FErrSource:='CHAR(A)';
  1441. AssertException(ESQLParser,@TestStringError);
  1442. end;
  1443. procedure TTestTypeParser.TestStringTypeErrors3;
  1444. begin
  1445. FErrSource:='CHAR(1]';
  1446. AssertException(ESQLParser,@TestStringError);
  1447. end;
  1448. procedure TTestTypeParser.TestTypeInt1;
  1449. Var
  1450. TD : TSQLTypeDefinition;
  1451. begin
  1452. TD:=TestType('INT',[],sdtInteger);
  1453. AssertTypeDefaults(TD);
  1454. end;
  1455. procedure TTestTypeParser.TestTypeInt2;
  1456. Var
  1457. TD : TSQLTypeDefinition;
  1458. begin
  1459. TD:=TestType('INT DEFAULT NULL',[],sdtInteger);
  1460. AssertNotNull('Have Default value',TD.DefaultValue);
  1461. CheckClass(TD.DefaultValue,TSQLNullLiteral);
  1462. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  1463. end;
  1464. procedure TTestTypeParser.TestTypeInt3;
  1465. Var
  1466. TD : TSQLTypeDefinition;
  1467. begin
  1468. TD:=TestType('INT DEFAULT 1',[],sdtInteger);
  1469. AssertNotNull('Have Default value',TD.DefaultValue);
  1470. CheckClass(TD.DefaultValue,TSQLIntegerLiteral);
  1471. AssertEquals('Correct default value ',1,TSQLIntegerLiteral(TD.DefaultValue).Value);
  1472. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  1473. end;
  1474. procedure TTestTypeParser.TestTypeInt4;
  1475. Var
  1476. TD : TSQLTypeDefinition;
  1477. begin
  1478. TD:=TestType('INT NOT NULL',[],sdtInteger);
  1479. AssertNull('No Default value',TD.DefaultValue);
  1480. AssertEquals('Required field',True,TD.NotNull);
  1481. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  1482. end;
  1483. procedure TTestTypeParser.TestTypeInt5;
  1484. Var
  1485. TD : TSQLTypeDefinition;
  1486. begin
  1487. TD:=TestType('INT [3]',[],sdtInteger);
  1488. AssertEquals('Array of length 3',3,TD.ArrayDim);
  1489. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  1490. end;
  1491. procedure TTestTypeParser.TestNumerical1;
  1492. Var
  1493. TD : TSQLTypeDefinition;
  1494. begin
  1495. TD:=TestType('NUMERIC (10)',[],sdtNumeric);
  1496. AssertEquals('Correct length',10,TD.Len);
  1497. end;
  1498. procedure TTestTypeParser.TestNumerical2;
  1499. Var
  1500. TD : TSQLTypeDefinition;
  1501. begin
  1502. TD:=TestType('NUMERIC (10,3)',[],sdtNumeric);
  1503. AssertEquals('Correct length',10,TD.Len);
  1504. AssertEquals('Correct scale',3,TD.Scale);
  1505. end;
  1506. procedure TTestTypeParser.TestNumerical3;
  1507. Var
  1508. TD : TSQLTypeDefinition;
  1509. begin
  1510. TD:=TestType('NUMERIC',[],sdtNumeric);
  1511. AssertEquals('Correct length',0,TD.Len);
  1512. AssertEquals('Correct scale',0,TD.Scale);
  1513. end;
  1514. procedure TTestTypeParser.TestNumericalError1;
  1515. begin
  1516. FErrSource:='NUMERIC ()';
  1517. AssertException(ESQLParser,@TestTypeError);
  1518. end;
  1519. procedure TTestTypeParser.TestNumericalError2;
  1520. begin
  1521. FErrSource:='NUMERIC (A)';
  1522. AssertException(ESQLParser,@TestTypeError);
  1523. end;
  1524. procedure TTestTypeParser.TestNumericalError3;
  1525. begin
  1526. FErrSource:='NUMERIC (,1)';
  1527. AssertException(ESQLParser,@TestTypeError);
  1528. end;
  1529. procedure TTestTypeParser.TestNumericalError4;
  1530. begin
  1531. FErrSource:='NUMERIC (1,)';
  1532. AssertException(ESQLParser,@TestTypeError);
  1533. end;
  1534. procedure TTestTypeParser.TestNumericalError5;
  1535. begin
  1536. FErrSource:='NUMERIC (1';
  1537. AssertException(ESQLParser,@TestTypeError);
  1538. end;
  1539. procedure TTestTypeParser.TestNumericalError6;
  1540. begin
  1541. FErrSource:='NUMERIC (1,';
  1542. AssertException(ESQLParser,@TestTypeError);
  1543. end;
  1544. procedure TTestTypeParser.TestNumericalError7;
  1545. begin
  1546. FErrSource:='NUMERIC (1 NOT';
  1547. AssertException(ESQLParser,@TestTypeError);
  1548. end;
  1549. procedure TTestTypeParser.TestBlob1;
  1550. Var
  1551. TD : TSQLTypeDefinition;
  1552. begin
  1553. TD:=TestType('BLOB sub_type 1 SEGMENT SIZE 80 CHARACTER SET UTF8',[],sdtBlob);
  1554. AssertEquals('Blob type 1',1,TD.BlobType);
  1555. AssertEquals('Blob segment size',80,TD.Len);
  1556. AssertEquals('Character set','UTF8',TD.Charset);
  1557. end;
  1558. procedure TTestTypeParser.TestBlob2;
  1559. Var
  1560. TD : TSQLTypeDefinition;
  1561. begin
  1562. TD:=TestType('BLOB (80,1) CHARACTER SET UTF8',[],sdtBlob);
  1563. AssertEquals('Blob type 1',1,TD.BlobType);
  1564. AssertEquals('Blob segment size',80,TD.Len);
  1565. AssertEquals('Character set','UTF8',TD.Charset);
  1566. end;
  1567. procedure TTestTypeParser.TestBlob3;
  1568. Var
  1569. TD : TSQLTypeDefinition;
  1570. begin
  1571. TD:=TestType('BLOB SEGMENT SIZE 80',[],sdtBlob);
  1572. AssertEquals('Blob type 0',0,TD.BlobType);
  1573. AssertEquals('Blob segment size',80,TD.Len);
  1574. AssertEquals('Character set','',TD.Charset);
  1575. end;
  1576. procedure TTestTypeParser.TestBlob4;
  1577. Var
  1578. TD : TSQLTypeDefinition;
  1579. begin
  1580. TD:=TestType('BLOB SUB_TYPE 1',[],sdtBlob);
  1581. AssertEquals('Blob type 1',1,TD.BlobType);
  1582. AssertEquals('Blob segment size',0,TD.Len);
  1583. AssertEquals('Character set','',TD.Charset);
  1584. end;
  1585. procedure TTestTypeParser.TestBlob5;
  1586. Var
  1587. TD : TSQLTypeDefinition;
  1588. begin
  1589. TD:=TestType('BLOB (80)',[],sdtBlob);
  1590. AssertEquals('Blob type 0',0,TD.BlobType);
  1591. AssertEquals('Blob segment size',80,TD.Len);
  1592. AssertEquals('Character set','',TD.Charset);
  1593. end;
  1594. procedure TTestTypeParser.TestBlob6;
  1595. Var
  1596. TD : TSQLTypeDefinition;
  1597. begin
  1598. TD:=TestType('BLOB',[],sdtBlob);
  1599. AssertEquals('Blob type 0',0,TD.BlobType);
  1600. AssertEquals('Blob segment size',0,TD.Len);
  1601. AssertEquals('Character set','',TD.Charset);
  1602. end;
  1603. procedure TTestTypeParser.TestBlob7;
  1604. var
  1605. TD : TSQLTypeDefinition;
  1606. begin
  1607. TD:=TestType('BLOB SUB_TYPE BINARY',[],sdtBlob);
  1608. AssertEquals('Blob type 0',0,TD.BlobType);
  1609. AssertEquals('Blob segment size',0,TD.Len);
  1610. AssertEquals('Character set','',TD.Charset);
  1611. end;
  1612. procedure TTestTypeParser.TestBlob8;
  1613. var
  1614. TD : TSQLTypeDefinition;
  1615. begin
  1616. TD:=TestType('BLOB SUB_TYPE TEXT',[],sdtBlob);
  1617. AssertEquals('Blob type 1',1,TD.BlobType);
  1618. AssertEquals('Blob segment size',0,TD.Len);
  1619. AssertEquals('Character set','',TD.Charset);
  1620. end;
  1621. procedure TTestTypeParser.TestSmallInt;
  1622. Var
  1623. TD : TSQLTypeDefinition;
  1624. begin
  1625. TD:=TestType('SMALLINT',[],sdtSmallint);
  1626. end;
  1627. procedure TTestTypeParser.TestFloat;
  1628. Var
  1629. TD : TSQLTypeDefinition;
  1630. begin
  1631. TD:=TestType('FLOAT',[],sdtFloat);
  1632. end;
  1633. procedure TTestTypeParser.TestDoublePrecision;
  1634. var
  1635. TD : TSQLTypeDefinition;
  1636. begin
  1637. TD:=TestType('DOUBLE PRECISION',[],sdtDoublePrecision);
  1638. end;
  1639. procedure TTestTypeParser.TestDoublePrecisionDefault;
  1640. var
  1641. TD : TSQLTypeDefinition;
  1642. begin
  1643. TD:=TestType('DOUBLE PRECISION DEFAULT 0',[],sdtDoublePrecision);
  1644. end;
  1645. procedure TTestTypeParser.TestBlobError1;
  1646. begin
  1647. FerrSource:='BLOB (1,)';
  1648. AssertException(ESQLParser,@TestTypeError);
  1649. end;
  1650. procedure TTestTypeParser.TestBlobError2;
  1651. begin
  1652. FerrSource:='BLOB 1,)';
  1653. // EAssertionfailed, due to not EOF
  1654. AssertException(EAssertionFailedError,@TestTypeError);
  1655. end;
  1656. procedure TTestTypeParser.TestBlobError3;
  1657. begin
  1658. FerrSource:='BLOB (80) SUB_TYPE 3';
  1659. AssertException(ESQLParser,@TestTypeError);
  1660. end;
  1661. procedure TTestTypeParser.TestBlobError4;
  1662. begin
  1663. FerrSource:='BLOB CHARACTER UTF8';
  1664. AssertException(ESQLParser,@TestTypeError);
  1665. end;
  1666. procedure TTestTypeParser.TestBlobError5;
  1667. begin
  1668. FerrSource:='BLOB (80) SEGMENT SIZE 80';
  1669. AssertException(ESQLParser,@TestTypeError);
  1670. end;
  1671. procedure TTestTypeParser.TestBlobError6;
  1672. begin
  1673. FerrSource:='BLOB (A)';
  1674. AssertException(ESQLParser,@TestTypeError);
  1675. end;
  1676. procedure TTestTypeParser.TestBlobError7;
  1677. begin
  1678. FerrSource:='BLOB (1';
  1679. AssertException(ESQLParser,@TestTypeError);
  1680. end;
  1681. { --------------------------------------------------------------------
  1682. TTestCheckParser
  1683. --------------------------------------------------------------------}
  1684. procedure TTestCheckParser.TestCheckNotNull;
  1685. Var
  1686. B : TSQLBinaryExpression;
  1687. begin
  1688. B:=TSQLBinaryExpression(TestCheck('VALUE IS NOT NULL',TSQLBinaryExpression));
  1689. AssertEquals('IS NOT operator,',boISNot,B.Operation);
  1690. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1691. AssertLiteralExpr('Right is null',B.Right,TSQLNullLiteral);
  1692. end;
  1693. procedure TTestCheckParser.TestCheckNull;
  1694. Var
  1695. B : TSQLBinaryExpression;
  1696. begin
  1697. B:=TSQLBinaryExpression(TestCheck('VALUE IS NULL',TSQLBinaryExpression));
  1698. AssertEquals('IS operator,',boIS,B.Operation);
  1699. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1700. AssertLiteralExpr('Right is null',B.Right,TSQLNullLiteral);
  1701. end;
  1702. procedure TTestCheckParser.TestCheckBraces;
  1703. Var
  1704. B : TSQLBinaryExpression;
  1705. begin
  1706. B:=TSQLBinaryExpression(TestCheck('(VALUE IS NULL)',TSQLBinaryExpression));
  1707. AssertEquals('IS operator,',boIS,B.Operation);
  1708. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1709. AssertLiteralExpr('Right is null',B.Right,TSQLNullLiteral);
  1710. end;
  1711. procedure TTestCheckParser.TestCheckBracesError;
  1712. begin
  1713. FErrSource:='(VALUE IS NOT NULL ME )';
  1714. AssertException('Error in braces.', ESQLParser,@TestCheckError);
  1715. end;
  1716. procedure TTestCheckParser.TestCheckParamError;
  1717. begin
  1718. FErrSource:='VALUE <> :P';
  1719. AssertException('Parameter.', ESQLParser,@TestCheckError);
  1720. end;
  1721. procedure TTestCheckParser.TestCheckIdentifierError;
  1722. begin
  1723. FErrSource:='(X IS NOT NULL)';
  1724. AssertException('Error in check: identifier.', ESQLParser,@TestCheckError);
  1725. end;
  1726. procedure TTestCheckParser.TestIsEqual;
  1727. Var
  1728. B : TSQLBinaryExpression;
  1729. begin
  1730. B:=TSQLBinaryExpression(TestCheck('VALUE = 3',TSQLBinaryExpression));
  1731. AssertEquals('Equal operator',boEq,B.Operation);
  1732. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1733. AssertLiteralExpr('Right is integer',B.Right,TSQLIntegerLiteral);
  1734. end;
  1735. procedure TTestCheckParser.TestIsNotEqual1;
  1736. Var
  1737. B : TSQLBinaryExpression;
  1738. begin
  1739. B:=TSQLBinaryExpression(TestCheck('VALUE <> 3',TSQLBinaryExpression));
  1740. AssertEquals('Not Equal operator',boNE,B.Operation);
  1741. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1742. AssertLiteralExpr('Right is integer',B.Right,TSQLIntegerLiteral);
  1743. end;
  1744. procedure TTestCheckParser.TestIsNotEqual2;
  1745. Var
  1746. B : TSQLBinaryExpression;
  1747. begin
  1748. B:=TSQLBinaryExpression(TestCheck('VALUE != 3',TSQLBinaryExpression));
  1749. AssertEquals('ENot qual operator',boNE,B.Operation);
  1750. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1751. AssertLiteralExpr('Right is integer',B.Right,TSQLIntegerLiteral);
  1752. end;
  1753. procedure TTestCheckParser.TestGreaterThan;
  1754. Var
  1755. B : TSQLBinaryExpression;
  1756. begin
  1757. B:=TSQLBinaryExpression(TestCheck('VALUE > 3',TSQLBinaryExpression));
  1758. AssertEquals('Greater than operator',boGT,B.Operation);
  1759. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1760. AssertLiteralExpr('Right is integer',B.Right,TSQLIntegerLiteral);
  1761. end;
  1762. procedure TTestCheckParser.TestGreaterThanEqual1;
  1763. Var
  1764. B : TSQLBinaryExpression;
  1765. begin
  1766. B:=TSQLBinaryExpression(TestCheck('VALUE >= 3',TSQLBinaryExpression));
  1767. AssertEquals('Greater or Equal operator',boGE,B.Operation);
  1768. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1769. AssertLiteralExpr('Right is integer',B.Right,TSQLIntegerLiteral);
  1770. end;
  1771. procedure TTestCheckParser.TestGreaterThanEqual2;
  1772. Var
  1773. B : TSQLBinaryExpression;
  1774. begin
  1775. B:=TSQLBinaryExpression(TestCheck('VALUE !< 3',TSQLBinaryExpression));
  1776. AssertEquals('Greater or Equal operator',boGE,B.Operation);
  1777. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1778. AssertLiteralExpr('Right is integer',B.Right,TSQLIntegerLiteral);
  1779. end;
  1780. procedure TTestCheckParser.TestLessThan;
  1781. Var
  1782. B : TSQLBinaryExpression;
  1783. begin
  1784. B:=TSQLBinaryExpression(TestCheck('VALUE < 3',TSQLBinaryExpression));
  1785. AssertEquals('Less than operator',boLT,B.Operation);
  1786. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1787. AssertLiteralExpr('Right is integer',B.Right,TSQLIntegerLiteral);
  1788. end;
  1789. procedure TTestCheckParser.TestLessThanEqual1;
  1790. Var
  1791. B : TSQLBinaryExpression;
  1792. begin
  1793. B:=TSQLBinaryExpression(TestCheck('VALUE <= 3',TSQLBinaryExpression));
  1794. AssertEquals('Less or Equal operator',boLE,B.Operation);
  1795. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1796. AssertLiteralExpr('Right is integer',B.Right,TSQLIntegerLiteral);
  1797. end;
  1798. procedure TTestCheckParser.TestLessThanEqual2;
  1799. Var
  1800. B : TSQLBinaryExpression;
  1801. begin
  1802. B:=TSQLBinaryExpression(TestCheck('VALUE !> 3',TSQLBinaryExpression));
  1803. AssertEquals('Less or Equal operator',boLE,B.Operation);
  1804. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1805. AssertLiteralExpr('Right is integer',B.Right,TSQLIntegerLiteral);
  1806. end;
  1807. procedure TTestCheckParser.TestLike;
  1808. Var
  1809. B : TSQLBinaryExpression;
  1810. begin
  1811. B:=TSQLBinaryExpression(TestCheck('VALUE LIKE ''%3''',TSQLBinaryExpression));
  1812. AssertEquals('Like operator',boLike,B.Operation);
  1813. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1814. AssertLiteralExpr('Right is string',B.Right,TSQLStringLiteral);
  1815. end;
  1816. procedure TTestCheckParser.TestNotLike;
  1817. Var
  1818. B : TSQLBinaryExpression;
  1819. U : TSQLUnaryExpression;
  1820. begin
  1821. U:=TSQLUnaryExpression(TestCheck('VALUE NOT LIKE ''%3''',TSQLUnaryExpression));
  1822. AssertEquals('Like operator',uoNot,U.Operation);
  1823. CheckClass(U.Operand,TSQLBinaryExpression);
  1824. B:=TSQLBinaryExpression(U.Operand);
  1825. AssertEquals('Like operator',boLike,B.Operation);
  1826. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1827. AssertLiteralExpr('Right is string',B.Right,TSQLStringLiteral);
  1828. end;
  1829. procedure TTestCheckParser.TestContaining;
  1830. Var
  1831. B : TSQLBinaryExpression;
  1832. begin
  1833. B:=TSQLBinaryExpression(TestCheck('VALUE CONTAINING ''3''',TSQLBinaryExpression));
  1834. AssertEquals('Like operator',boContaining,B.Operation);
  1835. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1836. AssertLiteralExpr('Right is string',B.Right,TSQLStringLiteral);
  1837. end;
  1838. procedure TTestCheckParser.TestNotContaining;
  1839. Var
  1840. B : TSQLBinaryExpression;
  1841. U : TSQLUnaryExpression;
  1842. begin
  1843. U:=TSQLUnaryExpression(TestCheck('VALUE NOT CONTAINING ''3''',TSQLUnaryExpression));
  1844. AssertEquals('Like operator',uoNot,U.Operation);
  1845. CheckClass(U.Operand,TSQLBinaryExpression);
  1846. B:=TSQLBinaryExpression(U.Operand);
  1847. AssertEquals('Like operator',boContaining,B.Operation);
  1848. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1849. AssertLiteralExpr('Right is string',B.Right,TSQLStringLiteral);
  1850. end;
  1851. procedure TTestCheckParser.TestStarting;
  1852. Var
  1853. B : TSQLBinaryExpression;
  1854. begin
  1855. B:=TSQLBinaryExpression(TestCheck('VALUE STARTING ''3''',TSQLBinaryExpression));
  1856. AssertEquals('Starting operator',boStarting,B.Operation);
  1857. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1858. AssertLiteralExpr('Right is string',B.Right,TSQLStringLiteral);
  1859. end;
  1860. procedure TTestCheckParser.TestNotStarting;
  1861. Var
  1862. B : TSQLBinaryExpression;
  1863. U : TSQLUnaryExpression;
  1864. begin
  1865. U:=TSQLUnaryExpression(TestCheck('VALUE NOT STARTING ''3''',TSQLUnaryExpression));
  1866. AssertEquals('Not operator',uoNot,U.Operation);
  1867. CheckClass(U.Operand,TSQLBinaryExpression);
  1868. B:=TSQLBinaryExpression(U.Operand);
  1869. AssertEquals('Starting operator',boStarting,B.Operation);
  1870. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1871. AssertLiteralExpr('Right is string',B.Right,TSQLStringLiteral);
  1872. end;
  1873. procedure TTestCheckParser.TestStartingWith;
  1874. Var
  1875. B : TSQLBinaryExpression;
  1876. begin
  1877. B:=TSQLBinaryExpression(TestCheck('VALUE STARTING WITH ''3''',TSQLBinaryExpression));
  1878. AssertEquals('Starting operator',boStarting,B.Operation);
  1879. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1880. AssertLiteralExpr('Right is string',B.Right,TSQLStringLiteral);
  1881. end;
  1882. procedure TTestCheckParser.TestNotStartingWith;
  1883. Var
  1884. B : TSQLBinaryExpression;
  1885. U : TSQLUnaryExpression;
  1886. begin
  1887. U:=TSQLUnaryExpression(TestCheck('VALUE NOT STARTING WITH ''3''',TSQLUnaryExpression));
  1888. AssertEquals('Not operator',uoNot,U.Operation);
  1889. CheckClass(U.Operand,TSQLBinaryExpression);
  1890. B:=TSQLBinaryExpression(U.Operand);
  1891. AssertEquals('Starting operator',boStarting,B.Operation);
  1892. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1893. AssertLiteralExpr('Right is string',B.Right,TSQLStringLiteral);
  1894. end;
  1895. procedure TTestCheckParser.TestBetween;
  1896. Var
  1897. T : TSQLTernaryExpression;
  1898. begin
  1899. T:=TSQLTernaryExpression(TestCheck('VALUE BETWEEN 1 AND 5',TSQLTernaryExpression));
  1900. AssertEquals('Like operator',tobetween,T.Operation);
  1901. AssertLiteralExpr('Left is value',T.Left,TSQLValueLiteral);
  1902. AssertLiteralExpr('Middle is integer',T.Middle,TSQLIntegerLiteral);
  1903. AssertLiteralExpr('Right is integer',T.Right,TSQLIntegerLiteral);
  1904. end;
  1905. procedure TTestCheckParser.TestNotBetween;
  1906. Var
  1907. U : TSQLUnaryExpression;
  1908. T : TSQLTernaryExpression;
  1909. begin
  1910. U:=TSQLUnaryExpression(TestCheck('VALUE NOT BETWEEN 1 AND 5',TSQLUnaryExpression));
  1911. AssertEquals('Not operator',uoNot,U.Operation);
  1912. CheckClass(U.Operand,TSQLTernaryExpression);
  1913. T:=TSQLTernaryExpression(U.Operand);
  1914. AssertEquals('Like operator',tobetween,T.Operation);
  1915. AssertLiteralExpr('Left is value',T.Left,TSQLValueLiteral);
  1916. AssertLiteralExpr('Middle is integer',T.Middle,TSQLIntegerLiteral);
  1917. AssertLiteralExpr('Right is integer',T.Right,TSQLIntegerLiteral);
  1918. end;
  1919. procedure TTestCheckParser.TestLikeEscape;
  1920. Var
  1921. T : TSQLTernaryExpression;
  1922. begin
  1923. T:=TSQLTernaryExpression(TestCheck('VALUE LIKE ''%2'' ESCAPE ''3''',TSQLTernaryExpression));
  1924. AssertEquals('Like operator',toLikeEscape,T.Operation);
  1925. AssertLiteralExpr('Left is value',T.Left,TSQLValueLiteral);
  1926. AssertLiteralExpr('Middle is string',T.Middle,TSQLStringLiteral);
  1927. AssertLiteralExpr('Right is string',T.Right,TSQLStringLiteral);
  1928. end;
  1929. procedure TTestCheckParser.TestNotLikeEscape;
  1930. Var
  1931. U : TSQLUnaryExpression;
  1932. T : TSQLTernaryExpression;
  1933. begin
  1934. U:=TSQLUnaryExpression(TestCheck('VALUE NOT LIKE ''%2'' ESCAPE ''3''',TSQLUnaryExpression));
  1935. AssertEquals('Not operator',uoNot,U.Operation);
  1936. CheckClass(U.Operand,TSQLTernaryExpression);
  1937. T:=TSQLTernaryExpression(U.Operand);
  1938. AssertEquals('Like operator',toLikeEscape,T.Operation);
  1939. AssertLiteralExpr('Left is value',T.Left,TSQLValueLiteral);
  1940. AssertLiteralExpr('Middle is string',T.Middle,TSQLStringLiteral);
  1941. AssertLiteralExpr('Right is string',T.Right,TSQLStringLiteral);
  1942. end;
  1943. procedure TTestCheckParser.TestAnd;
  1944. Var
  1945. T,B : TSQLBinaryExpression;
  1946. begin
  1947. T:=TSQLBinaryExpression(TestCheck('VALUE > 4 AND Value < 11',TSQLBinaryExpression));
  1948. AssertEquals('And operator',boand,T.Operation);
  1949. CheckClass(T.Left,TSQLBinaryExpression);
  1950. CheckClass(T.Right,TSQLBinaryExpression);
  1951. B:=TSQLBinaryExpression(T.Left);
  1952. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1953. AssertEquals('Less than operator',boGT,B.Operation);
  1954. AssertLiteralExpr('Right is value',B.Right,TSQLIntegerLiteral);
  1955. B:=TSQLBinaryExpression(T.Right);
  1956. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1957. AssertEquals('Less than operator',boLT,B.Operation);
  1958. AssertLiteralExpr('Right is value',B.Right,TSQLIntegerLiteral);
  1959. end;
  1960. procedure TTestCheckParser.TestOr;
  1961. Var
  1962. T,B : TSQLBinaryExpression;
  1963. begin
  1964. T:=TSQLBinaryExpression(TestCheck('VALUE < 4 or Value > 11',TSQLBinaryExpression));
  1965. AssertEquals('And operator',boor,T.Operation);
  1966. CheckClass(T.Left,TSQLBinaryExpression);
  1967. CheckClass(T.Right,TSQLBinaryExpression);
  1968. B:=TSQLBinaryExpression(T.Left);
  1969. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1970. AssertEquals('Less than operator',boLT,B.Operation);
  1971. AssertLiteralExpr('Right is value',B.Right,TSQLIntegerLiteral);
  1972. B:=TSQLBinaryExpression(T.Right);
  1973. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1974. AssertEquals('Less than operator',boGT,B.Operation);
  1975. AssertLiteralExpr('Right is value',B.Right,TSQLIntegerLiteral);
  1976. end;
  1977. procedure TTestCheckParser.TestNotOr;
  1978. Var
  1979. T,B : TSQLBinaryExpression;
  1980. begin
  1981. T:=TSQLBinaryExpression(TestCheck('VALUE IS NOT NULL or Value > 11',TSQLBinaryExpression));
  1982. AssertEquals('And operator',boor,T.Operation);
  1983. CheckClass(T.Left,TSQLBinaryExpression);
  1984. CheckClass(T.Right,TSQLBinaryExpression);
  1985. B:=TSQLBinaryExpression(T.Left);
  1986. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1987. AssertEquals('Is not null operator',boisNot,B.Operation);
  1988. AssertLiteralExpr('Right is value',B.Right,TSQLNullLiteral);
  1989. B:=TSQLBinaryExpression(T.Right);
  1990. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  1991. AssertEquals('Less than operator',boGT,B.Operation);
  1992. AssertLiteralExpr('Right is value',B.Right,TSQLIntegerLiteral);
  1993. end;
  1994. { TTestDomainParser }
  1995. procedure TTestDomainParser.TestSimpleDomain;
  1996. Var
  1997. P : TSQLCreateOrAlterStatement;
  1998. D : TSQLCreateDomainStatement;
  1999. T : TSQLTypeDefinition;
  2000. begin
  2001. P:=TestCreateStatement('CREATE DOMAIN A INT','A',TSQLCreateDomainStatement);
  2002. CheckClass(P,TSQLCreateDomainStatement);
  2003. D:=TSQLCreateDomainStatement(P);
  2004. AssertNotNull('Have type Definition',D.TypeDefinition);
  2005. T:=D.TypeDefinition;
  2006. AssertTypeDefaults(T);
  2007. AssertEquals('Integer data type',sdtInteger,T.DataType);
  2008. end;
  2009. procedure TTestDomainParser.TestSimpleDomainAs;
  2010. Var
  2011. P : TSQLCreateOrAlterStatement;
  2012. D : TSQLCreateDomainStatement;
  2013. T : TSQLTypeDefinition;
  2014. begin
  2015. P:=TestCreateStatement('CREATE DOMAIN A AS INT','A',TSQLCreateDomainStatement);
  2016. CheckClass(P,TSQLCreateDomainStatement);
  2017. D:=TSQLCreateDomainStatement(P);
  2018. AssertNotNull('Have type Definition',D.TypeDefinition);
  2019. T:=D.TypeDefinition;
  2020. AssertTypeDefaults(T);
  2021. AssertEquals('Integer data type',sdtInteger,T.DataType);
  2022. end;
  2023. procedure TTestDomainParser.TestNotNullDomain;
  2024. Var
  2025. P : TSQLCreateOrAlterStatement;
  2026. D : TSQLCreateDomainStatement;
  2027. T : TSQLTypeDefinition;
  2028. begin
  2029. P:=TestCreateStatement('CREATE DOMAIN A INT NOT NULL','A',TSQLCreateDomainStatement);
  2030. CheckClass(P,TSQLCreateDomainStatement);
  2031. D:=TSQLCreateDomainStatement(P);
  2032. AssertNotNull('Have type Definition',D.TypeDefinition);
  2033. T:=D.TypeDefinition;
  2034. AssertEquals('Integer data type',sdtInteger,T.DataType);
  2035. AssertEquals('Not null',True,T.NotNull);
  2036. end;
  2037. procedure TTestDomainParser.TestDefaultNotNullDomain;
  2038. Var
  2039. P : TSQLCreateOrAlterStatement;
  2040. D : TSQLCreateDomainStatement;
  2041. T : TSQLTypeDefinition;
  2042. begin
  2043. P:=TestCreateStatement('CREATE DOMAIN A INT DEFAULT 2 NOT NULL','A',TSQLCreateDomainStatement);
  2044. CheckClass(P,TSQLCreateDomainStatement);
  2045. D:=TSQLCreateDomainStatement(P);
  2046. AssertNotNull('Have type Definition',D.TypeDefinition);
  2047. T:=D.TypeDefinition;
  2048. AssertNotNull('Have default value',T.DefaultValue);
  2049. CheckClass(T.DefaultValue,TSQLINtegerLiteral);
  2050. AssertEquals('Integer data type',sdtInteger,T.DataType);
  2051. AssertEquals('Not null',True,T.NotNull);
  2052. end;
  2053. procedure TTestDomainParser.TestCheckDomain;
  2054. var
  2055. P : TSQLCreateOrAlterStatement;
  2056. D : TSQLCreateDomainStatement;
  2057. T : TSQLTypeDefinition;
  2058. begin
  2059. P:=TestCreateStatement('CREATE DOMAIN A AS CHAR(8) CHECK (VALUE STARTING WITH ''V'')','A',TSQLCreateDomainStatement);
  2060. CheckClass(P,TSQLCreateDomainStatement);
  2061. D:=TSQLCreateDomainStatement(P);
  2062. AssertNotNull('Have type Definition',D.TypeDefinition);
  2063. T:=D.TypeDefinition;
  2064. AssertNull('No default value',T.DefaultValue);
  2065. AssertEquals('Character data type',sdtChar,T.DataType);
  2066. AssertEquals('Not null must be allowed',False,T.NotNull);
  2067. end;
  2068. procedure TTestDomainParser.TestDefaultCheckNotNullDomain;
  2069. var
  2070. P : TSQLCreateOrAlterStatement;
  2071. D : TSQLCreateDomainStatement;
  2072. T : TSQLTypeDefinition;
  2073. begin
  2074. P:=TestCreateStatement(
  2075. 'CREATE DOMAIN DEFCHECKNOTN AS VARCHAR(1) DEFAULT ''s'' CHECK (VALUE IN (''s'',''h'',''A'')) NOT NULL',
  2076. 'DEFCHECKNOTN',TSQLCreateDomainStatement);
  2077. CheckClass(P,TSQLCreateDomainStatement);
  2078. D:=TSQLCreateDomainStatement(P);
  2079. AssertNotNull('Have type Definition',D.TypeDefinition);
  2080. T:=D.TypeDefinition;
  2081. AssertNotNull('Have default value',T.DefaultValue);
  2082. AssertEquals('Varchar data type',sdtVarChar,T.DataType);
  2083. AssertEquals('Not null',True,T.NotNull);
  2084. end;
  2085. procedure TTestDomainParser.TestAlterDomainDropDefault;
  2086. begin
  2087. TestCreateStatement('ALTER DOMAIN A DROP DEFAULT','A',TSQLAlterDomainDropDefaultStatement);
  2088. end;
  2089. procedure TTestDomainParser.TestAlterDomainDropCheck;
  2090. begin
  2091. TestCreateStatement('ALTER DOMAIN A DROP CONSTRAINT','A',TSQLAlterDomainDropCheckStatement);
  2092. end;
  2093. procedure TTestDomainParser.TestAlterDomainAddCheck;
  2094. Var
  2095. P : TSQLCreateOrAlterStatement;
  2096. D : TSQLAlterDomainAddCheckStatement;
  2097. B : TSQLBinaryExpression;
  2098. begin
  2099. P:=TestCreateStatement('ALTER DOMAIN A ADD CHECK (VALUE IS NOT NULL)','A',TSQLAlterDomainAddCheckStatement);
  2100. D:=TSQLAlterDomainAddCheckStatement(P);
  2101. AssertNotNull('Have check',D.Check);
  2102. CheckClass(D.Check,TSQLBinaryExpression);
  2103. B:=TSQLBinaryExpression(D.Check);
  2104. AssertEquals('Is not null operator',boIsNot,B.Operation);
  2105. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  2106. AssertEquals('Is not null operator',boisNot,B.Operation);
  2107. AssertLiteralExpr('Right is value',B.Right,TSQLNullLiteral);
  2108. end;
  2109. procedure TTestDomainParser.TestAlterDomainAddConstraintCheck;
  2110. Var
  2111. P : TSQLCreateOrAlterStatement;
  2112. D : TSQLAlterDomainAddCheckStatement;
  2113. B : TSQLBinaryExpression;
  2114. begin
  2115. P:=TestCreateStatement('ALTER DOMAIN A ADD CONSTRAINT CHECK (VALUE IS NOT NULL)','A',TSQLAlterDomainAddCheckStatement);
  2116. D:=TSQLAlterDomainAddCheckStatement(P);
  2117. AssertNotNull('Have check',D.Check);
  2118. CheckClass(D.Check,TSQLBinaryExpression);
  2119. B:=TSQLBinaryExpression(D.Check);
  2120. AssertEquals('Is not null operation',boIsNot,B.Operation);
  2121. AssertLiteralExpr('Left is value',B.Left,TSQLValueLiteral);
  2122. AssertEquals('Is not null operator',boisNot,B.Operation);
  2123. AssertLiteralExpr('Right is value',B.Right,TSQLNullLiteral);
  2124. end;
  2125. procedure TTestDomainParser.TestAlterDomainAddConstraintError;
  2126. begin
  2127. FErrSource:='ALTER DOMAIN A ADD CONSTRAINT (VALUE IS NOT NULL)';
  2128. AssertException(ESQLParser,@TestParseError);
  2129. end;
  2130. procedure TTestDomainParser.TestAlterDomainSetDefault;
  2131. Var
  2132. P : TSQLCreateOrAlterStatement;
  2133. D : TSQLAlterDomainSetDefaultStatement;
  2134. begin
  2135. P:=TestCreateStatement('ALTER DOMAIN A SET DEFAULT NULL','A',TSQLAlterDomainSetDefaultStatement);
  2136. D:=TSQLAlterDomainSetDefaultStatement(P);
  2137. AssertNotNull('Have default',D.DefaultValue);
  2138. CheckClass(D.DefaultValue,TSQLNullLiteral);
  2139. end;
  2140. procedure TTestDomainParser.TestAlterDomainRename;
  2141. Var
  2142. P : TSQLCreateOrAlterStatement;
  2143. D : TSQLAlterDomainRenameStatement;
  2144. begin
  2145. P:=TestCreateStatement('ALTER DOMAIN A B','A',TSQLAlterDomainRenameStatement);
  2146. D:=TSQLAlterDomainRenameStatement(P);
  2147. AssertIdentifierName('New name','B',D.NewName);
  2148. end;
  2149. procedure TTestDomainParser.TestAlterDomainNewType;
  2150. Var
  2151. P : TSQLCreateOrAlterStatement;
  2152. D : TSQLAlterDomainTypeStatement;
  2153. begin
  2154. P:=TestCreateStatement('ALTER DOMAIN A TYPE CHAR(10)','A',TSQLAlterDomainTypeStatement);
  2155. D:=TSQLAlterDomainTypeStatement(P);
  2156. AssertNotNull('Have type definition',D.NewType);
  2157. AssertEquals('Char type',sdtChar,D.NewType.DataType);
  2158. AssertEquals('Char type of len 10',10,D.NewType.Len);
  2159. end;
  2160. procedure TTestDomainParser.TestAlterDomainNewTypeError1;
  2161. begin
  2162. FErrSource:='ALTER DOMAIN A TYPE INT NOT NULL';
  2163. AssertException(ESQLParser,@TestParseError);
  2164. end;
  2165. procedure TTestDomainParser.TestAlterDomainNewTypeError2;
  2166. begin
  2167. FErrSource:='ALTER DOMAIN A TYPE INT DEFAULT 1';
  2168. AssertException(ESQLParser,@TestParseError);
  2169. end;
  2170. procedure TTestDomainParser.TestAlterDomainDropCheckError;
  2171. begin
  2172. FErrSource:='ALTER DOMAIN A DROP CHECK';
  2173. AssertException(ESQLParser,@TestParseError);
  2174. end;
  2175. { TTestExceptionParser }
  2176. procedure TTestExceptionParser.TestException;
  2177. Var
  2178. P : TSQLCreateOrAlterStatement;
  2179. E : TSQLCreateExceptionStatement;
  2180. begin
  2181. P:=TestCreateStatement('CREATE EXCEPTION A ''A message''','A',TSQLCreateExceptionStatement);
  2182. E:=TSQLCreateExceptionStatement(P);
  2183. AssertNotNull('Have message',E.ExceptionMessage);
  2184. AssertEquals('Message','A message',E.ExceptionMessage.Value)
  2185. end;
  2186. procedure TTestExceptionParser.TestAlterException;
  2187. Var
  2188. P : TSQLCreateOrAlterStatement;
  2189. E : TSQLCreateExceptionStatement;
  2190. begin
  2191. P:=TestCreateStatement('ALTER EXCEPTION A ''A massage''','A',TSQLAlterExceptionStatement);
  2192. E:=TSQLCreateExceptionStatement(P);
  2193. AssertNotNull('Have message',E.ExceptionMessage);
  2194. AssertEquals('Message','A massage',E.ExceptionMessage.Value)
  2195. end;
  2196. procedure TTestExceptionParser.TestExceptionError1;
  2197. begin
  2198. FErrSource:='CREATE EXCEPTION NOT';
  2199. ASsertException(ESQLParser,@TestParseError);
  2200. end;
  2201. procedure TTestExceptionParser.TestExceptionError2;
  2202. begin
  2203. FErrSource:='CREATE EXCEPTION A NOT';
  2204. ASsertException(ESQLParser,@TestParseError);
  2205. end;
  2206. { TTestRoleParser }
  2207. procedure TTestRoleParser.TestCreateRole;
  2208. begin
  2209. TestCreateStatement('CREATE ROLE A','A',TSQLCreateROLEStatement);
  2210. end;
  2211. procedure TTestRoleParser.TestAlterRole;
  2212. begin
  2213. FErrSource:='ALTER ROLE A';
  2214. ASsertException(ESQLParser,@TestParseError);
  2215. end;
  2216. { TTestIndexParser }
  2217. procedure TTestIndexParser.TestAlterindexActive;
  2218. Var
  2219. A : TSQLAlterIndexStatement;
  2220. begin
  2221. A:=TSQLAlterIndexStatement(TestCreateStatement('ALTER INDEX A ACTIVE','A',TSQLAlterIndexStatement));
  2222. AssertEquals('Active',False,A.Inactive);
  2223. end;
  2224. procedure TTestIndexParser.TestAlterindexInactive;
  2225. Var
  2226. A : TSQLAlterIndexStatement;
  2227. begin
  2228. A:=TSQLAlterIndexStatement(TestCreateStatement('ALTER INDEX A INACTIVE','A',TSQLAlterIndexStatement));
  2229. AssertEquals('Inactive',True,A.Inactive);
  2230. end;
  2231. procedure TTestIndexParser.TestCreateIndexSimple;
  2232. Var
  2233. C : TSQLCreateIndexStatement;
  2234. begin
  2235. C:=TSQLCreateIndexStatement(TestCreateStatement('CREATE INDEX A ON B (C)','A',TSQLCreateIndexStatement));
  2236. If Not (C.Options=[]) then
  2237. Fail('Options empty');
  2238. AssertIdentifiername('Correct table name','B',C.TableName);
  2239. AssertNotNull('Have fieldlist',C.FieldNames);
  2240. AssertEquals('Number of fields',1,C.FieldNames.Count);
  2241. AssertIdentifiername('Field name','C',C.FieldNames[0]);
  2242. end;
  2243. procedure TTestIndexParser.TestIndexIndexDouble;
  2244. Var
  2245. C : TSQLCreateIndexStatement;
  2246. begin
  2247. C:=TSQLCreateIndexStatement(TestCreateStatement('CREATE INDEX A ON B (C,D)','A',TSQLCreateIndexStatement));
  2248. If Not (C.Options=[]) then
  2249. Fail('Options empty');
  2250. AssertIdentifiername('Correct table name','B',C.TableName);
  2251. AssertNotNull('Have fieldlist',C.FieldNames);
  2252. AssertEquals('Number of fields',2,C.FieldNames.Count);
  2253. AssertIdentifiername('Field name 1','C',C.FieldNames[0]);
  2254. AssertIdentifiername('Field name 2','D',C.FieldNames[1]);
  2255. end;
  2256. procedure TTestIndexParser.TestIndexError1;
  2257. begin
  2258. FErrSource:='ALTER UNIQUE INDEX A ACTIVE';
  2259. AssertException(ESQLParser,@TestParseError);
  2260. end;
  2261. procedure TTestIndexParser.TestIndexError2;
  2262. begin
  2263. FErrSource:='ALTER ASCENDING INDEX A ACTIVE';
  2264. AssertException(ESQLParser,@TestParseError);
  2265. end;
  2266. procedure TTestIndexParser.TestIndexError3;
  2267. begin
  2268. FErrSource:='ALTER DESCENDING INDEX A ACTIVE';
  2269. AssertException(ESQLParser,@TestParseError);
  2270. end;
  2271. procedure TTestIndexParser.TestIndexError4;
  2272. begin
  2273. FErrSource:='CREATE INDEX A ON B';
  2274. AssertException(ESQLParser,@TestParseError);
  2275. end;
  2276. procedure TTestIndexParser.TestIndexError5;
  2277. begin
  2278. FErrSource:='CREATE INDEX A ON B ()';
  2279. AssertException(ESQLParser,@TestParseError);
  2280. end;
  2281. procedure TTestIndexParser.TestIndexError6;
  2282. begin
  2283. FErrSource:='CREATE INDEX A ON B (A,)';
  2284. AssertException(ESQLParser,@TestParseError);
  2285. end;
  2286. procedure TTestIndexParser.TestCreateIndexUnique;
  2287. Var
  2288. C : TSQLCreateIndexStatement;
  2289. begin
  2290. C:=TSQLCreateIndexStatement(TestCreateStatement('CREATE UNIQUE INDEX A ON B (C)','A',TSQLCreateIndexStatement));
  2291. If not ([ioUnique]=C.Options) then
  2292. Fail('Not Unique index');
  2293. AssertIdentifierName('Have table name','B',C.TableName);
  2294. AssertNotNull('Have fieldlist',C.FieldNames);
  2295. AssertEquals('Number of fields',1,C.FieldNames.Count);
  2296. AssertIdentifierName('Correct field name','C',C.FieldNames[0]);
  2297. end;
  2298. procedure TTestIndexParser.TestCreateIndexUniqueAscending;
  2299. Var
  2300. C : TSQLCreateIndexStatement;
  2301. begin
  2302. C:=TSQLCreateIndexStatement(TestCreateStatement('CREATE UNIQUE ASCENDING INDEX A ON B (C)','A',TSQLCreateIndexStatement));
  2303. If not ([ioUnique,ioAscending ]=C.Options) then
  2304. Fail('Not Unique ascending index');
  2305. AssertIdentifierName('Have table name','B',C.TableName);
  2306. AssertNotNull('Have fieldlist',C.FieldNames);
  2307. AssertEquals('Number of fields',1,C.FieldNames.Count);
  2308. AssertIdentifierName('Correct field name','C',C.FieldNames[0]);
  2309. end;
  2310. procedure TTestIndexParser.TestCreateIndexUniqueDescending;
  2311. Var
  2312. C : TSQLCreateIndexStatement;
  2313. begin
  2314. C:=TSQLCreateIndexStatement(TestCreateStatement('CREATE UNIQUE DESCENDING INDEX A ON B (C)','A',TSQLCreateIndexStatement));
  2315. If not ([ioUnique,ioDescending]=C.Options) then
  2316. Fail('Not Unique descending index');
  2317. AssertIdentifierName('Have table name','B',C.TableName);
  2318. AssertNotNull('Have fieldlist',C.FieldNames);
  2319. AssertEquals('Number of fields',1,C.FieldNames.Count);
  2320. AssertIdentifierName('Correct field name','C',C.FieldNames[0]);
  2321. end;
  2322. procedure TTestIndexParser.TestCreateIndexAscending;
  2323. Var
  2324. C : TSQLCreateIndexStatement;
  2325. begin
  2326. C:=TSQLCreateIndexStatement(TestCreateStatement('CREATE ASCENDING INDEX A ON B (C)','A',TSQLCreateIndexStatement));
  2327. If not ([ioAscending]=C.Options) then
  2328. Fail('Not ascending index');
  2329. AssertIdentifierName('Have table name','B',C.TableName);
  2330. AssertNotNull('Have fieldlist',C.FieldNames);
  2331. AssertEquals('Number of fields',1,C.FieldNames.Count);
  2332. AssertIdentifierName('Correct field name','C',C.FieldNames[0]);
  2333. end;
  2334. procedure TTestIndexParser.TestCreateIndexDescending;
  2335. Var
  2336. C : TSQLCreateIndexStatement;
  2337. begin
  2338. C:=TSQLCreateIndexStatement(TestCreateStatement('CREATE DESCENDING INDEX A ON B (C)','A',TSQLCreateIndexStatement));
  2339. If not ([ioDescending] = C.Options) then
  2340. Fail('Not descending index');
  2341. AssertIdentifierName('Table name','B',C.TableName);
  2342. AssertNotNull('Have fieldlist',C.FieldNames);
  2343. AssertEquals('Number of fields',1,C.FieldNames.Count);
  2344. AssertIdentifierName('Correct field name','C',C.FieldNames[0]);
  2345. end;
  2346. { TTestTableParser }
  2347. procedure TTestTableParser.DoTestCreateReferencesField(const ASource: String;
  2348. AOnUpdate, AOnDelete: TForeignKeyAction);
  2349. Var
  2350. C : TSQLCreateTableStatement;
  2351. F : TSQLTableFieldDef;
  2352. D : TSQLForeignKeyFieldConstraint;
  2353. begin
  2354. C:=TSQLCreateTableStatement(TestCreateStatement(ASource,'A',TSQLCreateTableStatement));
  2355. AssertEquals('One field',1,C.FieldDefs.Count);
  2356. AssertEquals('No constraints',0,C.Constraints.Count);
  2357. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2358. AssertIdentifierName('fieldname','B',F.FieldName);
  2359. AssertNotNull('Have field type',F.FieldType);
  2360. AssertEquals('Correct field type',sdtInteger,F.FieldType.DataType);
  2361. AssertEquals('Field can be NULL',false,F.FieldType.NotNull);
  2362. AssertNull('Have default',F.FieldType.DefaultValue);
  2363. AssertNotNull('Have constraint',F.FieldType.Constraint);
  2364. D:=TSQLForeignKeyFieldConstraint(CheckClass(F.FieldType.Constraint,TSQLForeignKeyFieldConstraint));
  2365. AssertNull('No constraint name',D.ConstraintName);
  2366. AssertIdentifierName('Correct table name','C',D.Definition.TableName);
  2367. AssertEquals('Correct field list count',1,D.Definition.FieldList.Count);
  2368. AssertIdentifierName('Correct field name','D',D.Definition.FieldList[0]);
  2369. AssertEquals('No on update action',AOnUpdate,D.Definition.OnUpdate);
  2370. AssertEquals('No on delete action',AOnDelete,D.Definition.OnDelete);
  2371. end;
  2372. procedure TTestTableParser.TestCreateOneSimpleField;
  2373. Var
  2374. C : TSQLCreateTableStatement;
  2375. F : TSQLTableFieldDef;
  2376. begin
  2377. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT)','A',TSQLCreateTableStatement));
  2378. AssertEquals('One field',1,C.FieldDefs.Count);
  2379. AssertEquals('No constraints',0,C.Constraints.Count);
  2380. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2381. AssertIdentifierName('fieldname','B',F.FieldName);
  2382. AssertNotNull('Have field type',F.FieldType);
  2383. AssertEquals('Correct field type',sdtInteger,F.FieldType.DataType);
  2384. end;
  2385. procedure TTestTableParser.TestCreateTwoSimpleFields;
  2386. Var
  2387. C : TSQLCreateTableStatement;
  2388. F : TSQLTableFieldDef;
  2389. begin
  2390. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT, C CHAR(5))','A',TSQLCreateTableStatement));
  2391. AssertEquals('Two fields',2,C.FieldDefs.Count);
  2392. AssertEquals('No constraints',0,C.Constraints.Count);
  2393. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2394. AssertIdentifierName('fieldname','B',F.FieldName);
  2395. AssertNotNull('Have field type',F.FieldType);
  2396. AssertEquals('Correct field type',sdtInteger,F.FieldType.DataType);
  2397. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[1],TSQLTableFieldDef));
  2398. AssertIdentifierName('fieldname','C',F.FieldName);
  2399. AssertNotNull('Have field type',F.FieldType);
  2400. AssertEquals('Correct field type',sdtChar,F.FieldType.DataType);
  2401. end;
  2402. procedure TTestTableParser.TestCreateOnePrimaryField;
  2403. Var
  2404. C : TSQLCreateTableStatement;
  2405. F : TSQLTableFieldDef;
  2406. P : TSQLPrimaryKeyFieldConstraint;
  2407. begin
  2408. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT PRIMARY KEY)','A',TSQLCreateTableStatement));
  2409. AssertEquals('One field',1,C.FieldDefs.Count);
  2410. AssertEquals('No constraints',0,C.Constraints.Count);
  2411. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2412. AssertIdentifierName('fieldname','B',F.FieldName);
  2413. AssertNotNull('Have field type',F.FieldType);
  2414. AssertEquals('Correct field type',sdtInteger,F.FieldType.DataType);
  2415. AssertNotNull('Have constraint',F.FieldType.Constraint);
  2416. P:=TSQLPrimaryKeyFieldConstraint(CheckClass(F.FieldType.Constraint,TSQLPrimaryKeyFieldConstraint));
  2417. AssertNull('No constraint name',P.ConstraintName);
  2418. end;
  2419. procedure TTestTableParser.TestCreateOneNamedPrimaryField;
  2420. Var
  2421. C : TSQLCreateTableStatement;
  2422. F : TSQLTableFieldDef;
  2423. P : TSQLPrimaryKeyFieldConstraint;
  2424. begin
  2425. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT CONSTRAINT C PRIMARY KEY)','A',TSQLCreateTableStatement));
  2426. AssertEquals('One field',1,C.FieldDefs.Count);
  2427. AssertEquals('No constraints',0,C.Constraints.Count);
  2428. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2429. AssertIdentifierName('fieldname','B',F.FieldName);
  2430. AssertNotNull('Have field type',F.FieldType);
  2431. AssertEquals('Correct field type',sdtInteger,F.FieldType.DataType);
  2432. AssertNotNull('Have constraint',F.FieldType.Constraint);
  2433. P:=TSQLPrimaryKeyFieldConstraint(CheckClass(F.FieldType.Constraint,TSQLPrimaryKeyFieldConstraint));
  2434. AssertIdentifierName('Constraint name','C',P.ConstraintName);
  2435. end;
  2436. procedure TTestTableParser.TestCreateOneUniqueField;
  2437. Var
  2438. C : TSQLCreateTableStatement;
  2439. F : TSQLTableFieldDef;
  2440. U : TSQLUniqueFieldConstraint;
  2441. begin
  2442. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT UNIQUE)','A',TSQLCreateTableStatement));
  2443. AssertEquals('One field',1,C.FieldDefs.Count);
  2444. AssertEquals('No constraints',0,C.Constraints.Count);
  2445. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2446. AssertIdentifierName('fieldname','B',F.FieldName);
  2447. AssertNotNull('Have field type',F.FieldType);
  2448. AssertEquals('Correct field type',sdtInteger,F.FieldType.DataType);
  2449. AssertNotNull('Have constraint',F.FieldType.Constraint);
  2450. U:=TSQLUniqueFieldConstraint(CheckClass(F.FieldType.Constraint,TSQLUniqueFieldConstraint));
  2451. AssertNull('No constraint name',U.ConstraintName);
  2452. end;
  2453. procedure TTestTableParser.TestCreateOneNamedUniqueField;
  2454. Var
  2455. C : TSQLCreateTableStatement;
  2456. F : TSQLTableFieldDef;
  2457. U : TSQLUniqueFieldConstraint;
  2458. begin
  2459. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT CONSTRAINT C UNIQUE)','A',TSQLCreateTableStatement));
  2460. AssertEquals('One field',1,C.FieldDefs.Count);
  2461. AssertEquals('No constraints',0,C.Constraints.Count);
  2462. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2463. AssertIdentifierName('fieldname','B',F.FieldName);
  2464. AssertNotNull('Have field type',F.FieldType);
  2465. AssertEquals('Correct field type',sdtInteger,F.FieldType.DataType);
  2466. AssertNotNull('Have constraint',F.FieldType.Constraint);
  2467. U:=TSQLUniqueFieldConstraint(CheckClass(F.FieldType.Constraint,TSQLUniqueFieldConstraint));
  2468. AssertIdentifierName('Constraint name','C',U.ConstraintName);
  2469. end;
  2470. procedure TTestTableParser.TestCreateNotNullPrimaryField;
  2471. Var
  2472. C : TSQLCreateTableStatement;
  2473. F : TSQLTableFieldDef;
  2474. begin
  2475. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT NOT NULL PRIMARY KEY)','A',TSQLCreateTableStatement));
  2476. AssertEquals('One field',1,C.FieldDefs.Count);
  2477. AssertEquals('No constraints',0,C.Constraints.Count);
  2478. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2479. AssertIdentifierName('fieldname','B',F.FieldName);
  2480. AssertNotNull('Have field type',F.FieldType);
  2481. AssertEquals('Correct field type',sdtInteger,F.FieldType.DataType);
  2482. AssertEquals('Field is not NULL',true,F.FieldType.NotNull);
  2483. AssertNotNull('Have constraint',F.FieldType.Constraint);
  2484. CheckClass(F.FieldType.Constraint,TSQLPrimaryKeyFieldConstraint);
  2485. end;
  2486. procedure TTestTableParser.TestCreateNotNullDefaultPrimaryField;
  2487. Var
  2488. C : TSQLCreateTableStatement;
  2489. F : TSQLTableFieldDef;
  2490. begin
  2491. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT DEFAULT 0 NOT NULL PRIMARY KEY)','A',TSQLCreateTableStatement));
  2492. AssertEquals('One field',1,C.FieldDefs.Count);
  2493. AssertEquals('No constraints',0,C.Constraints.Count);
  2494. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2495. AssertIdentifierName('fieldname','B',F.FieldName);
  2496. AssertNotNull('Have field type',F.FieldType);
  2497. AssertEquals('Correct field type',sdtInteger,F.FieldType.DataType);
  2498. AssertEquals('Field is not NULL',true,F.FieldType.NotNull);
  2499. AssertNotNull('Have default',F.FieldType.DefaultValue);
  2500. CheckClass(F.FieldType.DefaultValue,TSQLIntegerLiteral);
  2501. AssertNotNull('Have constraint',F.FieldType.Constraint);
  2502. CheckClass(F.FieldType.Constraint,TSQLPrimaryKeyFieldConstraint);
  2503. end;
  2504. procedure TTestTableParser.TestCreateCheckField;
  2505. Var
  2506. C : TSQLCreateTableStatement;
  2507. F : TSQLTableFieldDef;
  2508. B : TSQLBinaryExpression;
  2509. CC : TSQLCheckFieldConstraint;
  2510. begin
  2511. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT CHECK (B<>0))','A',TSQLCreateTableStatement));
  2512. AssertEquals('One field',1,C.FieldDefs.Count);
  2513. AssertEquals('No constraints',0,C.Constraints.Count);
  2514. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2515. AssertIdentifierName('fieldname','B',F.FieldName);
  2516. AssertNotNull('Have field type',F.FieldType);
  2517. AssertEquals('Correct field type',sdtInteger,F.FieldType.DataType);
  2518. AssertNull('Have no default',F.FieldType.DefaultValue);
  2519. AssertNull('Fieldtype has no check',F.FieldType.Check);
  2520. AssertNotNull('Field has constraint check',F.FieldType.Constraint);
  2521. CC:=TSQLCheckFieldConstraint(CheckClass(F.FieldType.Constraint,TSQLCheckFieldConstraint));
  2522. AssertNull('No constraint name',CC.ConstraintName);
  2523. B:=TSQLBinaryExpression(CheckClass(CC.Expression,TSQLBinaryExpression));
  2524. AssertEquals('Unequal check',boNE,B.Operation);
  2525. end;
  2526. procedure TTestTableParser.TestCreateNamedCheckField;
  2527. Var
  2528. C : TSQLCreateTableStatement;
  2529. F : TSQLTableFieldDef;
  2530. B : TSQLBinaryExpression;
  2531. CC : TSQLCheckFieldConstraint;
  2532. begin
  2533. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT CONSTRAINT C CHECK (B<>0))','A',TSQLCreateTableStatement));
  2534. AssertEquals('One field',1,C.FieldDefs.Count);
  2535. AssertEquals('No constraints',0,C.Constraints.Count);
  2536. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2537. AssertIdentifierName('fieldname','B',F.FieldName);
  2538. AssertNotNull('Have field type',F.FieldType);
  2539. AssertEquals('Correct field type',sdtInteger,F.FieldType.DataType);
  2540. AssertNull('Have no default',F.FieldType.DefaultValue);
  2541. AssertNull('Fieldtype has no check',F.FieldType.Check);
  2542. AssertNotNull('Field has constraint check',F.FieldType.Constraint);
  2543. CC:=TSQLCheckFieldConstraint(CheckClass(F.FieldType.Constraint,TSQLCheckFieldConstraint));
  2544. AssertidentifierName('Constraint name','C',CC.ConstraintName);
  2545. B:=TSQLBinaryExpression(CheckClass(CC.Expression,TSQLBinaryExpression));
  2546. AssertEquals('Unequal check',boNE,B.Operation);
  2547. end;
  2548. procedure TTestTableParser.TestCreateReferencesField;
  2549. begin
  2550. DoTestCreateReferencesField('CREATE TABLE A (B INT REFERENCES C(D))',fkaNone,fkaNone);
  2551. end;
  2552. procedure TTestTableParser.TestCreateReferencesOnUpdateCascadeField;
  2553. begin
  2554. DoTestCreateReferencesField('CREATE TABLE A (B INT REFERENCES C(D) ON UPDATE CASCADE)',fkaCascade,fkaNone);
  2555. end;
  2556. procedure TTestTableParser.TestCreateReferencesOnUpdateNoActionField;
  2557. begin
  2558. DoTestCreateReferencesField('CREATE TABLE A (B INT REFERENCES C(D) ON UPDATE NO ACTION)',fkaNoAction,fkaNone);
  2559. end;
  2560. procedure TTestTableParser.TestCreateReferencesOnUpdateSetDefaultField;
  2561. begin
  2562. DoTestCreateReferencesField('CREATE TABLE A (B INT REFERENCES C(D) ON UPDATE SET DEFAULT)',fkaSetDefault,fkaNone);
  2563. end;
  2564. procedure TTestTableParser.TestCreateReferencesOnUpdateSetNullField;
  2565. begin
  2566. DoTestCreateReferencesField('CREATE TABLE A (B INT REFERENCES C(D) ON UPDATE SET NULL)',fkaSetNull,fkaNone);
  2567. end;
  2568. procedure TTestTableParser.TestCreateReferencesOnDeleteCascadeField;
  2569. begin
  2570. DoTestCreateReferencesField('CREATE TABLE A (B INT REFERENCES C(D) ON DELETE CASCADE)',fkaNone,fkaCascade);
  2571. end;
  2572. procedure TTestTableParser.TestCreateReferencesOnDeleteNoActionField;
  2573. begin
  2574. DoTestCreateReferencesField('CREATE TABLE A (B INT REFERENCES C(D) ON DELETE NO ACTION)',fkaNone,fkaNoAction);
  2575. end;
  2576. procedure TTestTableParser.TestCreateReferencesOnDeleteSetDefaultField;
  2577. begin
  2578. DoTestCreateReferencesField('CREATE TABLE A (B INT REFERENCES C(D) ON DELETE SET DEFAULT)',fkaNone,fkaSetDefault);
  2579. end;
  2580. procedure TTestTableParser.TestCreateReferencesOnDeleteSetNullField;
  2581. begin
  2582. DoTestCreateReferencesField('CREATE TABLE A (B INT REFERENCES C(D) ON DELETE SET NULL)',fkaNone,fkaSetNull);
  2583. end;
  2584. procedure TTestTableParser.TestCreateReferencesOnUpdateAndDeleteSetNullField;
  2585. begin
  2586. DoTestCreateReferencesField('CREATE TABLE A (B INT REFERENCES C(D) ON UPDATE SET NULL ON DELETE SET NULL)',fkaSetNull,fkaSetNull);
  2587. end;
  2588. procedure TTestTableParser.TestCreateNamedReferencesField;
  2589. Var
  2590. C : TSQLCreateTableStatement;
  2591. F : TSQLTableFieldDef;
  2592. D : TSQLForeignKeyFieldConstraint;
  2593. begin
  2594. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT CONSTRAINT FK REFERENCES C(D))','A',TSQLCreateTableStatement));
  2595. AssertEquals('One field',1,C.FieldDefs.Count);
  2596. AssertEquals('No constraints',0,C.Constraints.Count);
  2597. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2598. AssertIdentifierName('fieldname','B',F.FieldName);
  2599. AssertNotNull('Have field type',F.FieldType);
  2600. AssertEquals('Correct field type',sdtInteger,F.FieldType.DataType);
  2601. AssertEquals('Field can be NULL',false,F.FieldType.NotNull);
  2602. AssertNull('Have default',F.FieldType.DefaultValue);
  2603. AssertNotNull('Have constraint',F.FieldType.Constraint);
  2604. D:=TSQLForeignKeyFieldConstraint(CheckClass(F.FieldType.Constraint,TSQLForeignKeyFieldConstraint));
  2605. AssertIdentifierName('Correct constraint name','FK',D.ConstraintName);
  2606. AssertIdentifierName('Correct table name','C',D.Definition.TableName);
  2607. AssertEquals('Correct field list count',1,D.Definition.FieldList.Count);
  2608. AssertIdentifierName('Correct field name','D',D.Definition.FieldList[0]);
  2609. end;
  2610. procedure TTestTableParser.TestCreateComputedByField;
  2611. Var
  2612. C : TSQLCreateTableStatement;
  2613. F : TSQLTableFieldDef;
  2614. B : TSQLBinaryExpression;
  2615. begin
  2616. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT, C INT, D COMPUTED BY (B+C))','A',TSQLCreateTableStatement));
  2617. AssertEquals('Three fields',3,C.FieldDefs.Count);
  2618. AssertEquals('No constraints',0,C.Constraints.Count);
  2619. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[2],TSQLTableFieldDef));
  2620. AssertIdentifierName('fieldname','D',F.FieldName);
  2621. AssertNull('No field type',F.FieldType);
  2622. AssertNotNull('Have computed by expression',F.ComputedBy);
  2623. B:=TSQLBinaryExpression(CheckClass(F.ComputedBy,TSQLBinaryExpression));
  2624. AssertEquals('Add operation',boAdd,B.Operation);
  2625. CheckClass(B.Left,TSQLIdentifierExpression);
  2626. AssertIdentifierName('Correct identifier','B',TSQLIdentifierExpression(B.Left).Identifier);
  2627. CheckClass(B.Right,TSQLIdentifierExpression);
  2628. AssertIdentifierName('Correct identifier','C',TSQLIdentifierExpression(B.Right).Identifier);
  2629. end;
  2630. procedure TTestTableParser.TestCreatePrimaryKeyConstraint;
  2631. Var
  2632. C : TSQLCreateTableStatement;
  2633. F : TSQLTableFieldDef;
  2634. P: TSQLTablePrimaryKeyConstraintDef;
  2635. begin
  2636. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT, PRIMARY KEY (B))','A',TSQLCreateTableStatement));
  2637. AssertEquals('One field',1,C.FieldDefs.Count);
  2638. AssertEquals('One constraints',1,C.Constraints.Count);
  2639. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2640. AssertIdentifierName('fieldname','B',F.FieldName);
  2641. P:=TSQLTablePrimaryKeyConstraintDef(CheckClass(C.Constraints[0],TSQLTablePrimaryKeyConstraintDef));
  2642. AssertNotNull('Fieldlist assigned',P.FieldList);
  2643. AssertNull('Constraint name empty',P.ConstraintName);
  2644. AssertEquals('One field in primary key',1,P.FieldList.Count);
  2645. AssertIdentifierName('fieldname','B',P.FieldList[0]);
  2646. end;
  2647. procedure TTestTableParser.TestCreateNamedPrimaryKeyConstraint;
  2648. Var
  2649. C : TSQLCreateTableStatement;
  2650. F : TSQLTableFieldDef;
  2651. P: TSQLTablePrimaryKeyConstraintDef;
  2652. begin
  2653. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT, CONSTRAINT A_PK PRIMARY KEY (B))','A',TSQLCreateTableStatement));
  2654. AssertEquals('One field',1,C.FieldDefs.Count);
  2655. AssertEquals('One constraints',1,C.Constraints.Count);
  2656. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2657. AssertIdentifierName('fieldname','B',F.FieldName);
  2658. P:=TSQLTablePrimaryKeyConstraintDef(CheckClass(C.Constraints[0],TSQLTablePrimaryKeyConstraintDef));
  2659. AssertNotNull('Fieldlist assigned',P.FieldList);
  2660. AssertIdentifierName('fieldname','A_PK',P.ConstraintName);
  2661. AssertEquals('One field in primary key',1,P.FieldList.Count);
  2662. AssertIdentifierName('fieldname','B',P.FieldList[0]);
  2663. end;
  2664. procedure TTestTableParser.TestCreateForeignKeyConstraint;
  2665. Var
  2666. C : TSQLCreateTableStatement;
  2667. F : TSQLTableFieldDef;
  2668. P: TSQLTableForeignKeyConstraintDef;
  2669. begin
  2670. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT, FOREIGN KEY (B) REFERENCES C(D))','A',TSQLCreateTableStatement));
  2671. AssertEquals('One field',1,C.FieldDefs.Count);
  2672. AssertEquals('One constraints',1,C.Constraints.Count);
  2673. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2674. AssertIdentifierName('fieldname','B',F.FieldName);
  2675. P:=TSQLTableForeignKeyConstraintDef(CheckClass(C.Constraints[0],TSQLTableForeignKeyConstraintDef));
  2676. AssertNotNull('Fieldlist assigned',P.FieldList);
  2677. AssertNull('Constraint name',P.ConstraintName);
  2678. AssertEquals('One field in foreign key',1,P.FieldList.Count);
  2679. AssertIdentifierName('fieldname','B',P.FieldList[0]);
  2680. AssertIdentifierName('Target table name','C',P.Definition.TableName);
  2681. AssertEquals('One field in primary key target',1,P.Definition.FieldList.Count);
  2682. AssertIdentifierName('target fieldname','D',P.Definition.FieldList[0]);
  2683. end;
  2684. procedure TTestTableParser.TestCreateNamedForeignKeyConstraint;
  2685. Var
  2686. C : TSQLCreateTableStatement;
  2687. F : TSQLTableFieldDef;
  2688. P: TSQLTableForeignKeyConstraintDef;
  2689. begin
  2690. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT, CONSTRAINT A_FK FOREIGN KEY (B) REFERENCES C(D))','A',TSQLCreateTableStatement));
  2691. AssertEquals('One field',1,C.FieldDefs.Count);
  2692. AssertEquals('One constraints',1,C.Constraints.Count);
  2693. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2694. AssertIdentifierName('fieldname','B',F.FieldName);
  2695. P:=TSQLTableForeignKeyConstraintDef(CheckClass(C.Constraints[0],TSQLTableForeignKeyConstraintDef));
  2696. AssertNotNull('Fieldlist assigned',P.FieldList);
  2697. AssertIdentifierName('fieldname','A_FK',P.ConstraintName);
  2698. AssertEquals('One field in foreign key',1,P.FieldList.Count);
  2699. AssertIdentifierName('fieldname','B',P.FieldList[0]);
  2700. AssertIdentifierName('Target table name','C',P.Definition.TableName);
  2701. AssertEquals('One field in primary key target',1,P.Definition.FieldList.Count);
  2702. AssertIdentifierName('target fieldname','D',P.Definition.FieldList[0]);
  2703. end;
  2704. procedure TTestTableParser.TestCreateUniqueConstraint;
  2705. Var
  2706. C : TSQLCreateTableStatement;
  2707. F : TSQLTableFieldDef;
  2708. P: TSQLTableUniqueConstraintDef;
  2709. begin
  2710. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT, UNIQUE (B))','A',TSQLCreateTableStatement));
  2711. AssertEquals('One field',1,C.FieldDefs.Count);
  2712. AssertEquals('One constraints',1,C.Constraints.Count);
  2713. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2714. AssertIdentifierName('fieldname','B',F.FieldName);
  2715. P:=TSQLTableUniqueConstraintDef(CheckClass(C.Constraints[0],TSQLTableUniqueConstraintDef));
  2716. AssertNotNull('Fieldlist assigned',P.FieldList);
  2717. AssertNull('Constraint name empty',P.ConstraintName);
  2718. AssertEquals('One field in primary key',1,P.FieldList.Count);
  2719. AssertIdentifierName('Name is correct','B',P.FieldList[0]);
  2720. end;
  2721. procedure TTestTableParser.TestCreateNamedUniqueConstraint;
  2722. Var
  2723. C : TSQLCreateTableStatement;
  2724. F : TSQLTableFieldDef;
  2725. P: TSQLTableUniqueConstraintDef;
  2726. begin
  2727. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT, CONSTRAINT U_A UNIQUE (B))','A',TSQLCreateTableStatement));
  2728. AssertEquals('One field',1,C.FieldDefs.Count);
  2729. AssertEquals('One constraints',1,C.Constraints.Count);
  2730. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2731. AssertIdentifierName('fieldname','B',F.FieldName);
  2732. P:=TSQLTableUniqueConstraintDef(CheckClass(C.Constraints[0],TSQLTableUniqueConstraintDef));
  2733. AssertNotNull('Fieldlist assigned',P.FieldList);
  2734. AssertIdentifierName('fieldname','U_A',P.ConstraintName);
  2735. AssertEquals('One field in primary key',1,P.FieldList.Count);
  2736. AssertIdentifierName('Name is correct','B',P.FieldList[0]);
  2737. end;
  2738. procedure TTestTableParser.TestCreateCheckConstraint;
  2739. Var
  2740. C : TSQLCreateTableStatement;
  2741. F : TSQLTableFieldDef;
  2742. B : TSQLBinaryExpression;
  2743. P: TSQLTableCheckConstraintDef;
  2744. begin
  2745. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT, CHECK (B<>0))','A',TSQLCreateTableStatement));
  2746. AssertEquals('One field',1,C.FieldDefs.Count);
  2747. AssertEquals('One constraints',1,C.Constraints.Count);
  2748. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2749. AssertIdentifierName('fieldname','B',F.FieldName);
  2750. P:=TSQLTableCheckConstraintDef(CheckClass(C.Constraints[0],TSQLTableCheckConstraintDef));
  2751. AssertNull('Constraint name empty',P.ConstraintName);
  2752. AssertNotNull('Check expression assigned',P.Check);
  2753. B:=TSQLBinaryExpression(CheckClass(P.Check,TSQLBinaryExpression));
  2754. AssertEquals('Unequal',boNE,B.Operation);
  2755. end;
  2756. procedure TTestTableParser.TestCreateNamedCheckConstraint;
  2757. Var
  2758. C : TSQLCreateTableStatement;
  2759. F : TSQLTableFieldDef;
  2760. B : TSQLBinaryExpression;
  2761. P: TSQLTableCheckConstraintDef;
  2762. begin
  2763. C:=TSQLCreateTableStatement(TestCreateStatement('CREATE TABLE A (B INT, CONSTRAINT C_A CHECK (B<>0))','A',TSQLCreateTableStatement));
  2764. AssertEquals('One field',1,C.FieldDefs.Count);
  2765. AssertEquals('One constraints',1,C.Constraints.Count);
  2766. F:=TSQLTableFieldDef(CheckClass(C.FieldDefs[0],TSQLTableFieldDef));
  2767. AssertIdentifierName('fieldname','B',F.FieldName);
  2768. P:=TSQLTableCheckConstraintDef(CheckClass(C.Constraints[0],TSQLTableCheckConstraintDef));
  2769. AssertIdentifierName('Constainrname','C_A',P.ConstraintName);
  2770. AssertNotNull('Check expression assigned',P.Check);
  2771. B:=TSQLBinaryExpression(CheckClass(P.Check,TSQLBinaryExpression));
  2772. AssertEquals('Not equal operation',boNE,B.Operation);
  2773. end;
  2774. procedure TTestTableParser.TestAlterDropField;
  2775. Var
  2776. A : TSQLAlterTableStatement;
  2777. D : TSQLDropTableFieldOperation;
  2778. begin
  2779. A:=TSQLAlterTableStatement(TestCreateStatement('ALTER TABLE A DROP B','A',TSQLAlterTableStatement));
  2780. AssertEquals('One operation',1,A.Operations.Count);
  2781. D:=TSQLDropTableFieldOperation(CheckClass(A.Operations[0],TSQLDropTableFieldOperation));
  2782. AssertidentifierName('Drop field name','B',D.ObjectName);
  2783. end;
  2784. procedure TTestTableParser.TestAlterDropFields;
  2785. Var
  2786. A : TSQLAlterTableStatement;
  2787. D : TSQLDropTableFieldOperation;
  2788. begin
  2789. A:=TSQLAlterTableStatement(TestCreateStatement('ALTER TABLE A DROP B, DROP C','A',TSQLAlterTableStatement));
  2790. AssertEquals('Two operations',2,A.Operations.Count);
  2791. D:=TSQLDropTableFieldOperation(CheckClass(A.Operations[0],TSQLDropTableFieldOperation));
  2792. AssertidentifierName('Drop field name','B',D.ObjectName);
  2793. D:=TSQLDropTableFieldOperation(CheckClass(A.Operations[1],TSQLDropTableFieldOperation));
  2794. AssertidentifierName('Drop field name','C',D.ObjectName);
  2795. end;
  2796. procedure TTestTableParser.TestAlterDropConstraint;
  2797. Var
  2798. A : TSQLAlterTableStatement;
  2799. D : TSQLDropTableConstraintOperation;
  2800. begin
  2801. A:=TSQLAlterTableStatement(TestCreateStatement('ALTER TABLE A DROP CONSTRAINT B','A',TSQLAlterTableStatement));
  2802. AssertEquals('One operation',1,A.Operations.Count);
  2803. D:=TSQLDropTableConstraintOperation(CheckClass(A.Operations[0],TSQLDropTableConstraintOperation));
  2804. AssertidentifierName('Drop field name','B',D.ObjectName);
  2805. end;
  2806. procedure TTestTableParser.TestAlterDropConstraints;
  2807. Var
  2808. A : TSQLAlterTableStatement;
  2809. D : TSQLDropTableConstraintOperation;
  2810. begin
  2811. A:=TSQLAlterTableStatement(TestCreateStatement('ALTER TABLE A DROP CONSTRAINT B, DROP CONSTRAINT C','A',TSQLAlterTableStatement));
  2812. AssertEquals('Two operations',2,A.Operations.Count);
  2813. D:=TSQLDropTableConstraintOperation(CheckClass(A.Operations[0],TSQLDropTableConstraintOperation));
  2814. AssertidentifierName('Drop Constraint name','B',D.ObjectName);
  2815. D:=TSQLDropTableConstraintOperation(CheckClass(A.Operations[1],TSQLDropTableConstraintOperation));
  2816. AssertidentifierName('Drop field name','C',D.ObjectName);
  2817. end;
  2818. procedure TTestTableParser.TestAlterRenameField;
  2819. Var
  2820. A : TSQLAlterTableStatement;
  2821. R : TSQLAlterTableFieldNameOperation;
  2822. begin
  2823. A:=TSQLAlterTableStatement(TestCreateStatement('ALTER TABLE A ALTER B TO C','A',TSQLAlterTableStatement));
  2824. AssertEquals('One operation',1,A.Operations.Count);
  2825. R:=TSQLAlterTableFieldNameOperation(CheckClass(A.Operations[0],TSQLAlterTableFieldNameOperation));
  2826. AssertidentifierName('Old field name','B',R.ObjectName);
  2827. AssertidentifierName('New field name','C',R.NewName);
  2828. end;
  2829. procedure TTestTableParser.TestAlterRenameColumnField;
  2830. Var
  2831. A : TSQLAlterTableStatement;
  2832. R : TSQLAlterTableFieldNameOperation;
  2833. begin
  2834. A:=TSQLAlterTableStatement(TestCreateStatement('ALTER TABLE A ALTER COLUMN B TO C','A',TSQLAlterTableStatement));
  2835. AssertEquals('One operation',1,A.Operations.Count);
  2836. R:=TSQLAlterTableFieldNameOperation(CheckClass(A.Operations[0],TSQLAlterTableFieldNameOperation));
  2837. AssertidentifierName('Old field name','B',R.ObjectName);
  2838. AssertidentifierName('New field name','C',R.NewName);
  2839. end;
  2840. procedure TTestTableParser.TestAlterFieldType;
  2841. Var
  2842. A : TSQLAlterTableStatement;
  2843. R : TSQLAlterTableFieldTypeOperation;
  2844. begin
  2845. A:=TSQLAlterTableStatement(TestCreateStatement('ALTER TABLE A ALTER COLUMN B TYPE INT','A',TSQLAlterTableStatement));
  2846. AssertEquals('One operation',1,A.Operations.Count);
  2847. R:=TSQLAlterTableFieldTypeOperation(CheckClass(A.Operations[0],TSQLAlterTableFieldTypeOperation));
  2848. AssertidentifierName('Old field name','B',R.ObjectName);
  2849. AssertNotNull('Have field type',R.NewType);
  2850. Checkclass(R.NewType,TSQLTypeDefinition);
  2851. AssertEquals('Correct data type',sdtInteger,R.NewType.DataType);
  2852. end;
  2853. procedure TTestTableParser.TestAlterFieldPosition;
  2854. Var
  2855. A : TSQLAlterTableStatement;
  2856. R : TSQLAlterTableFieldPositionOperation;
  2857. begin
  2858. A:=TSQLAlterTableStatement(TestCreateStatement('ALTER TABLE A ALTER COLUMN B POSITION 3','A',TSQLAlterTableStatement));
  2859. AssertEquals('One operation',1,A.Operations.Count);
  2860. R:=TSQLAlterTableFieldPositionOperation(CheckClass(A.Operations[0],TSQLAlterTableFieldPositionOperation));
  2861. AssertidentifierName('Old field name','B',R.ObjectName);
  2862. AssertEquals('Correct position',3,R.NewPosition);
  2863. end;
  2864. procedure TTestTableParser.TestAlterAddField;
  2865. Var
  2866. A : TSQLAlterTableStatement;
  2867. F : TSQLAlterTableAddFieldOperation;
  2868. D : TSQLTableFieldDef;
  2869. begin
  2870. A:=TSQLAlterTableStatement(TestCreateStatement('ALTER TABLE A ADD B INT','A',TSQLAlterTableStatement));
  2871. AssertEquals('One operation',1,A.Operations.Count);
  2872. F:=TSQLAlterTableAddFieldOperation(CheckClass(A.Operations[0],TSQLAlterTableAddFieldOperation));
  2873. AssertNotNull('Have element',F.Element);
  2874. D:=TSQLTableFieldDef(CheckClass(F.Element,TSQLTableFieldDef));
  2875. AssertIdentifierName('New field name','B',D.FieldName);
  2876. AssertNotNull('Have fielddef',D.FieldType);
  2877. AssertEquals('Correct field type',sdtINteger,D.FieldType.DataType);
  2878. end;
  2879. procedure TTestTableParser.TestAlterAddFields;
  2880. Var
  2881. A : TSQLAlterTableStatement;
  2882. F : TSQLAlterTableAddFieldOperation;
  2883. D : TSQLTableFieldDef;
  2884. begin
  2885. A:=TSQLAlterTableStatement(TestCreateStatement('ALTER TABLE A ADD B INT, ADD C CHAR(50)','A',TSQLAlterTableStatement));
  2886. AssertEquals('Two operations',2,A.Operations.Count);
  2887. F:=TSQLAlterTableAddFieldOperation(CheckClass(A.Operations[0],TSQLAlterTableAddFieldOperation));
  2888. AssertNotNull('Have element',F.Element);
  2889. D:=TSQLTableFieldDef(CheckClass(F.Element,TSQLTableFieldDef));
  2890. AssertIdentifierName('New field name','B',D.FieldName);
  2891. AssertNotNull('Have fielddef',D.FieldType);
  2892. AssertEquals('Correct field type',sdtINteger,D.FieldType.DataType);
  2893. F:=TSQLAlterTableAddFieldOperation(CheckClass(A.Operations[1],TSQLAlterTableAddFieldOperation));
  2894. AssertNotNull('Have element',F.Element);
  2895. D:=TSQLTableFieldDef(CheckClass(F.Element,TSQLTableFieldDef));
  2896. AssertIdentifierName('New field name','C',D.FieldName);
  2897. AssertNotNull('Have fielddef',D.FieldType);
  2898. AssertEquals('Correct field type',sdtChar,D.FieldType.DataType);
  2899. AssertEquals('Correct field lengthe',50,D.FieldType.Len);
  2900. end;
  2901. procedure TTestTableParser.TestAlterAddPrimarykey;
  2902. Var
  2903. A : TSQLAlterTableStatement;
  2904. F : TSQLAlterTableAddConstraintOperation;
  2905. D : TSQLTablePrimaryKeyConstraintDef;
  2906. begin
  2907. A:=TSQLAlterTableStatement(TestCreateStatement('ALTER TABLE A ADD PRIMARY KEY (B)','A',TSQLAlterTableStatement));
  2908. AssertEquals('One operation',1,A.Operations.Count);
  2909. F:=TSQLAlterTableAddConstraintOperation(CheckClass(A.Operations[0],TSQLAlterTableAddConstraintOperation));
  2910. AssertNotNull('Have element',F.Element);
  2911. D:=TSQLTablePrimaryKeyConstraintDef(CheckClass(F.Element,TSQLTablePrimaryKeyConstraintDef));
  2912. AssertNull('No constraint name',D.ConstraintName);
  2913. AssertEquals('Have 1 field',1,D.FieldList.Count);
  2914. AssertIdentifierName('fieldname','B',D.FieldList[0]);
  2915. end;
  2916. procedure TTestTableParser.TestAlterAddNamedPrimarykey;
  2917. Var
  2918. A : TSQLAlterTableStatement;
  2919. F : TSQLAlterTableAddConstraintOperation;
  2920. D : TSQLTablePrimaryKeyConstraintDef;
  2921. begin
  2922. A:=TSQLAlterTableStatement(TestCreateStatement('ALTER TABLE A ADD CONSTRAINT U_K PRIMARY KEY (B)','A',TSQLAlterTableStatement));
  2923. AssertEquals('One operation',1,A.Operations.Count);
  2924. F:=TSQLAlterTableAddConstraintOperation(CheckClass(A.Operations[0],TSQLAlterTableAddConstraintOperation));
  2925. AssertNotNull('Have element',F.Element);
  2926. D:=TSQLTablePrimaryKeyConstraintDef(CheckClass(F.Element,TSQLTablePrimaryKeyConstraintDef));
  2927. AssertIdentifierName('No constraint name','U_K',D.ConstraintName);
  2928. AssertEquals('Have 1 field',1,D.FieldList.Count);
  2929. AssertIdentifierName('fieldname','B',D.FieldList[0]);
  2930. end;
  2931. procedure TTestTableParser.TestAlterAddCheckConstraint;
  2932. Var
  2933. A : TSQLAlterTableStatement;
  2934. F : TSQLAlterTableAddConstraintOperation;
  2935. D : TSQLTableCheckConstraintDef;
  2936. begin
  2937. A:=TSQLAlterTableStatement(TestCreateStatement('ALTER TABLE A ADD CHECK (B<>0)','A',TSQLAlterTableStatement));
  2938. AssertEquals('One operation',1,A.Operations.Count);
  2939. F:=TSQLAlterTableAddConstraintOperation(CheckClass(A.Operations[0],TSQLAlterTableAddConstraintOperation));
  2940. AssertNotNull('Have element',F.Element);
  2941. D:=TSQLTableCheckConstraintDef(CheckClass(F.Element,TSQLTableCheckConstraintDef));
  2942. AssertNull('Constaintname',D.ConstraintName);
  2943. AssertNotNull('Check expression assigned',D.Check);
  2944. CheckClass(D.Check,TSQLBinaryExpression);
  2945. end;
  2946. procedure TTestTableParser.TestAlterAddNamedCheckConstraint;
  2947. Var
  2948. A : TSQLAlterTableStatement;
  2949. F : TSQLAlterTableAddConstraintOperation;
  2950. D : TSQLTableCheckConstraintDef;
  2951. begin
  2952. A:=TSQLAlterTableStatement(TestCreateStatement('ALTER TABLE A ADD CONSTRAINT C_A CHECK (B<>0)','A',TSQLAlterTableStatement));
  2953. AssertEquals('One operation',1,A.Operations.Count);
  2954. F:=TSQLAlterTableAddConstraintOperation(CheckClass(A.Operations[0],TSQLAlterTableAddConstraintOperation));
  2955. AssertNotNull('Have element',F.Element);
  2956. D:=TSQLTableCheckConstraintDef(CheckClass(F.Element,TSQLTableCheckConstraintDef));
  2957. AssertIdentifierName('Constaintname','C_A',D.ConstraintName);
  2958. AssertNotNull('Check expression assigned',D.Check);
  2959. CheckClass(D.Check,TSQLBinaryExpression);
  2960. end;
  2961. procedure TTestTableParser.TestAlterAddForeignkey;
  2962. Var
  2963. A : TSQLAlterTableStatement;
  2964. F : TSQLAlterTableAddConstraintOperation;
  2965. D : TSQLTableForeignKeyConstraintDef;
  2966. begin
  2967. A:=TSQLAlterTableStatement(TestCreateStatement('ALTER TABLE A ADD FOREIGN KEY (B) REFERENCES C(D)','A',TSQLAlterTableStatement));
  2968. AssertEquals('One operation',1,A.Operations.Count);
  2969. F:=TSQLAlterTableAddConstraintOperation(CheckClass(A.Operations[0],TSQLAlterTableAddConstraintOperation));
  2970. AssertNotNull('Have element',F.Element);
  2971. D:=TSQLTableForeignKeyConstraintDef(CheckClass(F.Element,TSQLTableForeignKeyConstraintDef));
  2972. AssertNull('No constraint name',D.ConstraintName);
  2973. AssertEquals('Have 1 field',1,D.FieldList.Count);
  2974. AssertIdentifierName('fieldname','B',D.FieldList[0]);
  2975. AssertIdentifierName('Target table name','C',D.Definition.TableName);
  2976. AssertEquals('One field in primary key target',1,D.Definition.FieldList.Count);
  2977. AssertIdentifierName('target fieldname','D',D.Definition.FieldList[0]);
  2978. end;
  2979. procedure TTestTableParser.TestAlterAddNamedForeignkey;
  2980. Var
  2981. A : TSQLAlterTableStatement;
  2982. F : TSQLAlterTableAddConstraintOperation;
  2983. D : TSQLTableForeignKeyConstraintDef;
  2984. begin
  2985. A:=TSQLAlterTableStatement(TestCreateStatement('ALTER TABLE A ADD CONSTRAINT F_A FOREIGN KEY (B) REFERENCES C(D)','A',TSQLAlterTableStatement));
  2986. AssertEquals('One operation',1,A.Operations.Count);
  2987. F:=TSQLAlterTableAddConstraintOperation(CheckClass(A.Operations[0],TSQLAlterTableAddConstraintOperation));
  2988. AssertNotNull('Have element',F.Element);
  2989. D:=TSQLTableForeignKeyConstraintDef(CheckClass(F.Element,TSQLTableForeignKeyConstraintDef));
  2990. AssertIdentifierName('constraint name','F_A',D.ConstraintName);
  2991. AssertEquals('Have 1 field',1,D.FieldList.Count);
  2992. AssertIdentifierName('fieldname','B',D.FieldList[0]);
  2993. AssertIdentifierName('Target table name','C',D.Definition.TableName);
  2994. AssertEquals('One field in primary key target',1,D.Definition.FieldList.Count);
  2995. AssertIdentifierName('target fieldname','D',D.Definition.FieldList[0]);
  2996. end;
  2997. { TTestDeleteParser }
  2998. function TTestDeleteParser.TestDelete(const ASource,ATable: String
  2999. ): TSQLDeleteStatement;
  3000. begin
  3001. CreateParser(ASource);
  3002. FToFree:=Parser.Parse;
  3003. Result:=TSQLDeleteStatement(CheckClass(FToFree,TSQLDeleteStatement));
  3004. AssertIdentifierName('Correct table name',ATable,Result.TableName);
  3005. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  3006. end;
  3007. procedure TTestDeleteParser.TestSimpleDelete;
  3008. Var
  3009. D : TSQLDeleteStatement;
  3010. begin
  3011. D:=TestDelete('DELETE FROM A','A');
  3012. AssertNull('No where',D.WhereClause);
  3013. end;
  3014. procedure TTestDeleteParser.TestSimpleDeleteAlias;
  3015. Var
  3016. D : TSQLDeleteStatement;
  3017. begin
  3018. D:=TestDelete('DELETE FROM A B','A');
  3019. AssertIdentifierName('Alias name','B',D.AliasName);
  3020. AssertNull('No where',D.WhereClause);
  3021. end;
  3022. procedure TTestDeleteParser.TestDeleteWhereNull;
  3023. Var
  3024. D : TSQLDeleteStatement;
  3025. B : TSQLBinaryExpression;
  3026. I : TSQLIdentifierExpression;
  3027. L : TSQLLiteralExpression;
  3028. begin
  3029. D:=TestDelete('DELETE FROM A WHERE B IS NULL','A');
  3030. AssertNotNull('No where',D.WhereClause);
  3031. B:=TSQLBinaryExpression(CheckClass(D.WhereClause,TSQLBinaryExpression));
  3032. AssertEquals('Is null operation',boIs,B.Operation);
  3033. I:=TSQLIdentifierExpression(CheckClass(B.Left,TSQLIdentifierExpression));
  3034. AssertIdentifierName('Correct field name','B',I.Identifier);
  3035. L:=TSQLLiteralExpression(CheckClass(B.Right,TSQLLiteralExpression));
  3036. CheckClass(L.Literal,TSQLNullLiteral);
  3037. end;
  3038. { TTestUpdateParser }
  3039. function TTestUpdateParser.TestUpdate(const ASource, ATable: String
  3040. ): TSQLUpdateStatement;
  3041. begin
  3042. CreateParser(ASource);
  3043. FToFree:=Parser.Parse;
  3044. Result:=TSQLUpdateStatement(CheckClass(FToFree,TSQLUpdateStatement));
  3045. AssertIdentifierName('Correct table name',ATable,Result.TableName);
  3046. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  3047. end;
  3048. procedure TTestUpdateParser.TestUpdateOneField;
  3049. Var
  3050. U : TSQLUpdateStatement;
  3051. P : TSQLUpdatePair;
  3052. E : TSQLLiteralExpression;
  3053. I : TSQLIntegerLiteral;
  3054. begin
  3055. U:=TestUpdate('UPDATE A SET B=1','A');
  3056. AssertEquals('One field updated',1,U.Values.Count);
  3057. P:=TSQLUpdatePair(CheckClass(U.Values[0],TSQLUpdatePair));
  3058. AssertIdentifierName('Correct field name','B',P.FieldName);
  3059. E:=TSQLLiteralExpression(CheckClass(P.Value,TSQLLiteralExpression));
  3060. I:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  3061. AssertEquals('Value 1',1,I.Value);
  3062. AssertNull('No where clause',U.WhereClause);
  3063. end;
  3064. procedure TTestUpdateParser.TestUpdateOneFieldFull;
  3065. Var
  3066. U : TSQLUpdateStatement;
  3067. P : TSQLUpdatePair;
  3068. E : TSQLLiteralExpression;
  3069. I : TSQLIntegerLiteral;
  3070. begin
  3071. U:=TestUpdate('UPDATE A SET A.B=1','A');
  3072. AssertEquals('One field updated',1,U.Values.Count);
  3073. P:=TSQLUpdatePair(CheckClass(U.Values[0],TSQLUpdatePair));
  3074. AssertIdentifierName('Correct field name','A.B',P.FieldName);
  3075. E:=TSQLLiteralExpression(CheckClass(P.Value,TSQLLiteralExpression));
  3076. I:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  3077. AssertEquals('Value 1',1,I.Value);
  3078. AssertNull('No where clause',U.WhereClause);
  3079. end;
  3080. procedure TTestUpdateParser.TestUpdateTwoFields;
  3081. Var
  3082. U : TSQLUpdateStatement;
  3083. P : TSQLUpdatePair;
  3084. E : TSQLLiteralExpression;
  3085. I : TSQLIntegerLiteral;
  3086. begin
  3087. U:=TestUpdate('UPDATE A SET B=1, C=2','A');
  3088. AssertEquals('One field updated',2,U.Values.Count);
  3089. P:=TSQLUpdatePair(CheckClass(U.Values[0],TSQLUpdatePair));
  3090. AssertIdentifierName('Correct field name','B',P.FieldName);
  3091. E:=TSQLLiteralExpression(CheckClass(P.Value,TSQLLiteralExpression));
  3092. I:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  3093. AssertEquals('Value 1',1,I.Value);
  3094. P:=TSQLUpdatePair(CheckClass(U.Values[1],TSQLUpdatePair));
  3095. AssertIdentifierName('Correct field name','C',P.FieldName);
  3096. E:=TSQLLiteralExpression(CheckClass(P.Value,TSQLLiteralExpression));
  3097. I:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  3098. AssertEquals('Value 2',2,I.Value);
  3099. AssertNull('No where clause',U.WhereClause);
  3100. end;
  3101. procedure TTestUpdateParser.TestUpdateOneFieldWhereIsNull;
  3102. Var
  3103. U : TSQLUpdateStatement;
  3104. P : TSQLUpdatePair;
  3105. E : TSQLLiteralExpression;
  3106. I : TSQLIntegerLiteral;
  3107. B : TSQLBinaryExpression;
  3108. IE : TSQLIdentifierExpression;
  3109. L : TSQLLiteralExpression;
  3110. begin
  3111. U:=TestUpdate('UPDATE A SET B=1 WHERE B IS NULL','A');
  3112. AssertEquals('One field updated',1,U.Values.Count);
  3113. P:=TSQLUpdatePair(CheckClass(U.Values[0],TSQLUpdatePair));
  3114. AssertIdentifierName('Correct field name','B',P.FieldName);
  3115. E:=TSQLLiteralExpression(CheckClass(P.Value,TSQLLiteralExpression));
  3116. I:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  3117. AssertEquals('Value 1',1,I.Value);
  3118. AssertNotNull('where clause',U.WhereClause);
  3119. B:=TSQLBinaryExpression(CheckClass(U.WhereClause,TSQLBinaryExpression));
  3120. AssertEquals('Is null operation',boIs,B.Operation);
  3121. IE:=TSQLIdentifierExpression(CheckClass(B.Left,TSQLIdentifierExpression));
  3122. AssertIdentifierName('Correct field name','B',IE.Identifier);
  3123. L:=TSQLLiteralExpression(CheckClass(B.Right,TSQLLiteralExpression));
  3124. CheckClass(L.Literal,TSQLNullLiteral);
  3125. end;
  3126. { TTestInsertParser }
  3127. function TTestInsertParser.TestInsert(const ASource, ATable: String
  3128. ): TSQLInsertStatement;
  3129. begin
  3130. CreateParser(ASource);
  3131. FToFree:=Parser.Parse;
  3132. Result:=TSQLInsertStatement(CheckClass(FToFree,TSQLInsertStatement));
  3133. AssertIdentifierName('Correct table name',ATable,Result.TableName);
  3134. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  3135. end;
  3136. procedure TTestInsertParser.TestInsertOneField;
  3137. Var
  3138. I : TSQLInsertStatement;
  3139. E : TSQLLiteralExpression;
  3140. L : TSQLIntegerLiteral;
  3141. begin
  3142. I:=TestInsert('INSERT INTO A (B) VALUES (1)','A');
  3143. AssertNotNull('Have fields',I.Fields);
  3144. AssertEquals('1 field',1,I.Fields.Count);
  3145. AssertIdentifierName('Correct field name','B',I.Fields[0]);
  3146. AssertNotNull('Have values',I.Values);
  3147. AssertEquals('Have 1 value',1,I.Values.Count);
  3148. E:=TSQLLiteralExpression(CheckClass(I.Values[0],TSQLLiteralExpression));
  3149. L:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  3150. AssertEquals('Correct value',1,L.Value);
  3151. end;
  3152. procedure TTestInsertParser.TestInsertTwoFields;
  3153. Var
  3154. I : TSQLInsertStatement;
  3155. E : TSQLLiteralExpression;
  3156. L : TSQLIntegerLiteral;
  3157. begin
  3158. I:=TestInsert('INSERT INTO A (B,C) VALUES (1,2)','A');
  3159. AssertNotNull('Have fields',I.Fields);
  3160. AssertEquals('2 fields',2,I.Fields.Count);
  3161. AssertIdentifierName('Correct field 1 name','B',I.Fields[0]);
  3162. AssertIdentifierName('Correct field 2 name','C',I.Fields[1]);
  3163. AssertNotNull('Have values',I.Values);
  3164. AssertEquals('Have 2 values',2,I.Values.Count);
  3165. E:=TSQLLiteralExpression(CheckClass(I.Values[0],TSQLLiteralExpression));
  3166. L:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  3167. AssertEquals('Correct value',1,L.Value);
  3168. E:=TSQLLiteralExpression(CheckClass(I.Values[1],TSQLLiteralExpression));
  3169. L:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  3170. AssertEquals('Correct value',2,L.Value);
  3171. end;
  3172. procedure TTestInsertParser.TestInsertOneValue;
  3173. Var
  3174. I : TSQLInsertStatement;
  3175. E : TSQLLiteralExpression;
  3176. L : TSQLIntegerLiteral;
  3177. begin
  3178. I:=TestInsert('INSERT INTO A VALUES (1)','A');
  3179. AssertNull('Have no fields',I.Fields);
  3180. AssertNotNull('Have values',I.Values);
  3181. AssertEquals('Have 1 value',1,I.Values.Count);
  3182. E:=TSQLLiteralExpression(CheckClass(I.Values[0],TSQLLiteralExpression));
  3183. L:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  3184. AssertEquals('Correct value',1,L.Value);
  3185. end;
  3186. procedure TTestInsertParser.TestInsertTwoValues;
  3187. Var
  3188. I : TSQLInsertStatement;
  3189. E : TSQLLiteralExpression;
  3190. L : TSQLIntegerLiteral;
  3191. begin
  3192. I:=TestInsert('INSERT INTO A VALUES (1,2)','A');
  3193. AssertNull('Have no fields',I.Fields);
  3194. AssertNotNull('Have values',I.Values);
  3195. AssertEquals('Have 2 values',2,I.Values.Count);
  3196. E:=TSQLLiteralExpression(CheckClass(I.Values[0],TSQLLiteralExpression));
  3197. L:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  3198. AssertEquals('Correct value',1,L.Value);
  3199. E:=TSQLLiteralExpression(CheckClass(I.Values[1],TSQLLiteralExpression));
  3200. L:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  3201. AssertEquals('Correct value',2,L.Value);
  3202. end;
  3203. { TTestSelectParser }
  3204. function TTestSelectParser.TestSelect(const ASource : String): TSQLSelectStatement;
  3205. begin
  3206. CreateParser(ASource);
  3207. FToFree:=Parser.Parse;
  3208. Result:=TSQLSelectStatement(CheckClass(FToFree,TSQLSelectStatement));
  3209. FSelect:=Result;
  3210. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  3211. end;
  3212. procedure TTestSelectParser.TestSelectError(const ASource: String);
  3213. begin
  3214. FErrSource:=ASource;
  3215. AssertException(ESQLParser,@TestParseError);
  3216. end;
  3217. procedure TTestSelectParser.TestSelectOneFieldOneTable;
  3218. begin
  3219. TestSelect('SELECT B FROM A');
  3220. AssertNull('No transaction name',Select.TransactionName);
  3221. AssertEquals('One field',1,Select.Fields.Count);
  3222. AssertField(Select.Fields[0],'B');
  3223. AssertEquals('One table',1,Select.Tables.Count);
  3224. AssertTable(Select.Tables[0],'A');
  3225. end;
  3226. procedure TTestSelectParser.TestSelectOneFieldOneTableTransaction;
  3227. begin
  3228. TestSelect('SELECT TRANSACTION C B FROM A');
  3229. AssertIdentifierName('Correct transaction name','C',Select.TransactionName);
  3230. AssertEquals('One field',1,Select.Fields.Count);
  3231. AssertField(Select.Fields[0],'B');
  3232. AssertEquals('One table',1,Select.Tables.Count);
  3233. AssertTable(Select.Tables[0],'A');
  3234. end;
  3235. procedure TTestSelectParser.TestSelectOneArrayFieldOneTable;
  3236. Var
  3237. E : TSQLIdentifierExpression;
  3238. begin
  3239. TestSelect('SELECT B[1] FROM A');
  3240. AssertEquals('One field',1,Select.Fields.Count);
  3241. AssertField(Select.Fields[0],'B');
  3242. E:=TSQLIdentifierExpression(CheckClass(TSQLSelectField(Select.Fields[0]).Expression,TSQLIdentifierExpression));
  3243. AssertEquals('Element 1 in array ',1,E.ElementIndex);
  3244. AssertEquals('One table',1,Select.Tables.Count);
  3245. AssertTable(Select.Tables[0],'A');
  3246. end;
  3247. procedure TTestSelectParser.TestSelectTwoFieldsOneTable;
  3248. begin
  3249. TestSelect('SELECT B,C FROM A');
  3250. AssertEquals('Two fields',2,Select.Fields.Count);
  3251. AssertField(Select.Fields[0],'B');
  3252. AssertField(Select.Fields[1],'C');
  3253. AssertEquals('One table',1,Select.Tables.Count);
  3254. AssertTable(Select.Tables[0],'A');
  3255. end;
  3256. procedure TTestSelectParser.TestSelectOneFieldAliasOneTable;
  3257. begin
  3258. TestSelect('SELECT B AS C FROM A');
  3259. AssertEquals('One field',1,Select.Fields.Count);
  3260. AssertField(Select.Fields[0],'B','C');
  3261. AssertEquals('One table',1,Select.Tables.Count);
  3262. AssertTable(Select.Tables[0],'A');
  3263. end;
  3264. procedure TTestSelectParser.TestSelectTwoFieldAliasesOneTable;
  3265. begin
  3266. TestSelect('SELECT B AS D,C AS E FROM A');
  3267. AssertEquals('Two fields',2,Select.Fields.Count);
  3268. AssertField(Select.Fields[0],'B','D');
  3269. AssertField(Select.Fields[1],'C','E');
  3270. AssertEquals('One table',1,Select.Tables.Count);
  3271. AssertTable(Select.Tables[0],'A');
  3272. end;
  3273. procedure TTestSelectParser.TestSelectOneTableFieldOneTable;
  3274. begin
  3275. TestSelect('SELECT A.B FROM A');
  3276. AssertEquals('One field',1,Select.Fields.Count);
  3277. // Field does not support linking/refering to a table, so the field name is
  3278. // assigned as A.B (instead of B with a <link to table A>)
  3279. AssertField(Select.Fields[0],'A.B');
  3280. AssertEquals('One table',1,Select.Tables.Count);
  3281. AssertTable(Select.Tables[0],'A');
  3282. end;
  3283. procedure TTestSelectParser.TestSelectOneDistinctFieldOneTable;
  3284. begin
  3285. TestSelect('SELECT DISTINCT B FROM A');
  3286. AssertEquals('DISTINCT Query',True,Select.Distinct);
  3287. AssertEquals('One field',1,Select.Fields.Count);
  3288. AssertField(Select.Fields[0],'B');
  3289. AssertEquals('One table',1,Select.Tables.Count);
  3290. AssertTable(Select.Tables[0],'A');
  3291. end;
  3292. procedure TTestSelectParser.TestSelectOneAllFieldOneTable;
  3293. begin
  3294. TestSelect('SELECT ALL B FROM A');
  3295. AssertEquals('ALL Query',True,Select.All);
  3296. AssertEquals('One field',1,Select.Fields.Count);
  3297. AssertField(Select.Fields[0],'B');
  3298. AssertEquals('One table',1,Select.Tables.Count);
  3299. AssertTable(Select.Tables[0],'A');
  3300. end;
  3301. procedure TTestSelectParser.TestSelectAsteriskOneTable;
  3302. begin
  3303. TestSelect('SELECT * FROM A');
  3304. AssertEquals('One field',1,Select.Fields.Count);
  3305. CheckClass(Select.Fields[0],TSQLSelectAsterisk);
  3306. AssertEquals('One table',1,Select.Tables.Count);
  3307. AssertTable(Select.Tables[0],'A');
  3308. end;
  3309. procedure TTestSelectParser.TestSelectDistinctAsteriskOneTable;
  3310. begin
  3311. TestSelect('SELECT DISTINCT * FROM A');
  3312. AssertEquals('DISTINCT Query',True,Select.Distinct);
  3313. AssertEquals('One field',1,Select.Fields.Count);
  3314. CheckClass(Select.Fields[0],TSQLSelectAsterisk);
  3315. AssertEquals('One table',1,Select.Tables.Count);
  3316. AssertTable(Select.Tables[0],'A');
  3317. end;
  3318. procedure TTestSelectParser.TestSelectOneFieldOneTableAlias;
  3319. begin
  3320. TestSelect('SELECT C.B FROM A C');
  3321. AssertEquals('One field',1,Select.Fields.Count);
  3322. AssertField(Select.Fields[0],'C.B');
  3323. AssertEquals('One table',1,Select.Tables.Count);
  3324. AssertTable(Select.Tables[0],'A');
  3325. end;
  3326. procedure TTestSelectParser.TestSelectOneFieldOneTableAsAlias;
  3327. begin
  3328. TestSelect('SELECT C.B FROM A AS C');
  3329. AssertEquals('One field',1,Select.Fields.Count);
  3330. AssertField(Select.Fields[0],'C.B');
  3331. AssertEquals('One table',1,Select.Tables.Count);
  3332. AssertTable(Select.Tables[0],'A');
  3333. end;
  3334. procedure TTestSelectParser.TestSelectTwoFieldsTwoTables;
  3335. begin
  3336. TestSelect('SELECT B,C FROM A,D');
  3337. AssertEquals('Two fields',2,Select.Fields.Count);
  3338. AssertField(Select.Fields[0],'B');
  3339. AssertField(Select.Fields[1],'C');
  3340. AssertEquals('Two table',2,Select.Tables.Count);
  3341. AssertTable(Select.Tables[0],'A');
  3342. AssertTable(Select.Tables[1],'D');
  3343. end;
  3344. procedure TTestSelectParser.TestSelectTwoFieldsTwoTablesJoin;
  3345. Var
  3346. J : TSQLJoinTableReference;
  3347. begin
  3348. TestSelect('SELECT B,C FROM A JOIN D ON E=F');
  3349. AssertEquals('Two fields',2,Select.Fields.Count);
  3350. AssertField(Select.Fields[0],'B');
  3351. AssertField(Select.Fields[1],'C');
  3352. AssertEquals('One table',1,Select.Tables.Count);
  3353. J:=AssertJoin(Select.Tables[0],'A','D',jtNone);
  3354. AssertJoinOn(J.JoinClause,'E','F',boEq);
  3355. end;
  3356. procedure TTestSelectParser.TestSelectTwoFieldsTwoInnerTablesJoin;
  3357. Var
  3358. J : TSQLJoinTableReference;
  3359. begin
  3360. TestSelect('SELECT B,C FROM A INNER JOIN D ON E=F');
  3361. AssertEquals('Two fields',2,Select.Fields.Count);
  3362. AssertField(Select.Fields[0],'B');
  3363. AssertField(Select.Fields[1],'C');
  3364. AssertEquals('One table',1,Select.Tables.Count);
  3365. J:=AssertJoin(Select.Tables[0],'A','D',jtInner);
  3366. AssertJoinOn(J.JoinClause,'E','F',boEq);
  3367. end;
  3368. procedure TTestSelectParser.TestSelectTwoFieldsTwoFullOuterTablesJoin;
  3369. Var
  3370. J : TSQLJoinTableReference;
  3371. begin
  3372. TestSelect('SELECT B,C FROM A FULL OUTER JOIN D ON E=F');
  3373. AssertEquals('Two fields',2,Select.Fields.Count);
  3374. AssertField(Select.Fields[0],'B');
  3375. AssertField(Select.Fields[1],'C');
  3376. AssertEquals('One table',1,Select.Tables.Count);
  3377. J:=AssertJoin(Select.Tables[0],'A','D',jtFullOuter);
  3378. AssertJoinOn(J.JoinClause,'E','F',boEq);
  3379. end;
  3380. procedure TTestSelectParser.TestSelectTwoFieldsTwoFullTablesJoin;
  3381. Var
  3382. J : TSQLJoinTableReference;
  3383. begin
  3384. TestSelect('SELECT B,C FROM A FULL JOIN D ON E=F');
  3385. AssertEquals('Two fields',2,Select.Fields.Count);
  3386. AssertField(Select.Fields[0],'B');
  3387. AssertField(Select.Fields[1],'C');
  3388. AssertEquals('One table',1,Select.Tables.Count);
  3389. J:=AssertJoin(Select.Tables[0],'A','D',jtFullOuter);
  3390. AssertJoinOn(J.JoinClause,'E','F',boEq);
  3391. end;
  3392. procedure TTestSelectParser.TestSelectTwoFieldsTwoLeftTablesJoin;
  3393. Var
  3394. J : TSQLJoinTableReference;
  3395. begin
  3396. TestSelect('SELECT B,C FROM A LEFT JOIN D ON E=F');
  3397. AssertEquals('Two fields',2,Select.Fields.Count);
  3398. AssertField(Select.Fields[0],'B');
  3399. AssertField(Select.Fields[1],'C');
  3400. AssertEquals('One table',1,Select.Tables.Count);
  3401. J:=AssertJoin(Select.Tables[0],'A','D',jtLeft);
  3402. AssertJoinOn(J.JoinClause,'E','F',boEq);
  3403. end;
  3404. procedure TTestSelectParser.TestSelectTwoFieldsTwoRightTablesJoin;
  3405. Var
  3406. J : TSQLJoinTableReference;
  3407. begin
  3408. TestSelect('SELECT B,C FROM A RIGHT JOIN D ON E=F');
  3409. AssertEquals('Two fields',2,Select.Fields.Count);
  3410. AssertField(Select.Fields[0],'B');
  3411. AssertField(Select.Fields[1],'C');
  3412. AssertEquals('One table',1,Select.Tables.Count);
  3413. J:=AssertJoin(Select.Tables[0],'A','D',jtRight);
  3414. AssertJoinOn(J.JoinClause,'E','F',boEq);
  3415. end;
  3416. procedure TTestSelectParser.TestSelectTwoFieldsThreeTablesJoin;
  3417. Var
  3418. J : TSQLJoinTableReference;
  3419. begin
  3420. TestSelect('SELECT B,C FROM A JOIN D ON E=F JOIN G ON (H=I)');
  3421. AssertEquals('Two fields',2,Select.Fields.Count);
  3422. AssertField(Select.Fields[0],'B');
  3423. AssertField(Select.Fields[1],'C');
  3424. AssertEquals('One table',1,Select.Tables.Count);
  3425. j:=AssertJoin(Select.Tables[0],'','G',jtNone);
  3426. AssertJoinOn(J.JoinClause,'H','I',boEq);
  3427. J:=AssertJoin(J.Left,'A','D',jtNone);
  3428. AssertJoinOn(J.JoinClause,'E','F',boEq);
  3429. end;
  3430. procedure TTestSelectParser.TestSelectTwoFieldsBracketThreeTablesJoin;
  3431. Var
  3432. J : TSQLJoinTableReference;
  3433. begin
  3434. TestSelect('SELECT B,C FROM (A JOIN D ON E=F) JOIN G ON (H=I)');
  3435. AssertEquals('Two fields',2,Select.Fields.Count);
  3436. AssertField(Select.Fields[0],'B');
  3437. AssertField(Select.Fields[1],'C');
  3438. AssertEquals('One table',1,Select.Tables.Count);
  3439. j:=AssertJoin(Select.Tables[0],'','G',jtNone);
  3440. AssertJoinOn(J.JoinClause,'H','I',boEq);
  3441. J:=AssertJoin(J.Left,'A','D',jtNone);
  3442. AssertJoinOn(J.JoinClause,'E','F',boEq);
  3443. end;
  3444. procedure TTestSelectParser.TestSelectTwoFieldsThreeBracketTablesJoin;
  3445. Var
  3446. J : TSQLJoinTableReference;
  3447. begin
  3448. TestSelect('SELECT B,C FROM A JOIN (D JOIN G ON E=F) ON (H=I)');
  3449. AssertEquals('Two fields',2,Select.Fields.Count);
  3450. AssertField(Select.Fields[0],'B');
  3451. AssertField(Select.Fields[1],'C');
  3452. AssertEquals('One table',1,Select.Tables.Count);
  3453. j:=AssertJoin(Select.Tables[0],'A','',jtNone);
  3454. AssertJoinOn(J.JoinClause,'H','I',boEq);
  3455. j:=AssertJoin(J.Right,'D','G',jtNone);
  3456. AssertJoinOn(J.JoinClause,'E','F',boEq);
  3457. end;
  3458. procedure TTestSelectParser.TestAggregateCount;
  3459. begin
  3460. TestSelect('SELECT COUNT(B) FROM A');
  3461. AssertEquals('One field',1,Select.Fields.Count);
  3462. AssertEquals('One table',1,Select.Tables.Count);
  3463. AssertTable(Select.Tables[0],'A');
  3464. AssertAggregate(Select.Fields[0],afCount,'B',aoNone,'');
  3465. end;
  3466. procedure TTestSelectParser.TestAggregateCountAsterisk;
  3467. begin
  3468. TestSelect('SELECT COUNT(*) FROM A');
  3469. AssertEquals('One field',1,Select.Fields.Count);
  3470. AssertEquals('One table',1,Select.Tables.Count);
  3471. AssertTable(Select.Tables[0],'A');
  3472. AssertAggregate(Select.Fields[0],afCount,'',aoAsterisk,'');
  3473. end;
  3474. procedure TTestSelectParser.TestAggregateCountAll;
  3475. begin
  3476. TestSelect('SELECT COUNT(ALL B) FROM A');
  3477. AssertEquals('One field',1,Select.Fields.Count);
  3478. AssertEquals('One table',1,Select.Tables.Count);
  3479. AssertTable(Select.Tables[0],'A');
  3480. AssertAggregate(Select.Fields[0],afCount,'B',aoAll,'');
  3481. end;
  3482. procedure TTestSelectParser.TestAggregateCountDistinct;
  3483. begin
  3484. TestSelect('SELECT COUNT(DISTINCT B) FROM A');
  3485. AssertEquals('One field',1,Select.Fields.Count);
  3486. AssertEquals('One table',1,Select.Tables.Count);
  3487. AssertTable(Select.Tables[0],'A');
  3488. AssertAggregate(Select.Fields[0],afCount,'B',aoDistinct,'');
  3489. end;
  3490. procedure TTestSelectParser.TestAggregateMax;
  3491. begin
  3492. TestSelect('SELECT MAX(B) FROM A');
  3493. AssertEquals('One field',1,Select.Fields.Count);
  3494. AssertEquals('One table',1,Select.Tables.Count);
  3495. AssertTable(Select.Tables[0],'A');
  3496. AssertAggregate(Select.Fields[0],afMax,'B',aoNone,'');
  3497. end;
  3498. procedure TTestSelectParser.TestAggregateMaxAsterisk;
  3499. begin
  3500. TestSelectError('SELECT Max(*) FROM A');
  3501. end;
  3502. procedure TTestSelectParser.TestAggregateMaxAll;
  3503. begin
  3504. TestSelect('SELECT MAX(ALL B) FROM A');
  3505. AssertEquals('One field',1,Select.Fields.Count);
  3506. AssertEquals('One table',1,Select.Tables.Count);
  3507. AssertTable(Select.Tables[0],'A');
  3508. AssertAggregate(Select.Fields[0],afMax,'B',aoAll,'');
  3509. end;
  3510. procedure TTestSelectParser.TestAggregateMaxDistinct;
  3511. begin
  3512. TestSelect('SELECT MAX(DISTINCT B) FROM A');
  3513. AssertEquals('One field',1,Select.Fields.Count);
  3514. AssertEquals('One table',1,Select.Tables.Count);
  3515. AssertTable(Select.Tables[0],'A');
  3516. AssertAggregate(Select.Fields[0],afMax,'B',aoDistinct,'');
  3517. end;
  3518. procedure TTestSelectParser.TestAggregateMin;
  3519. begin
  3520. TestSelect('SELECT Min(B) FROM A');
  3521. AssertEquals('One field',1,Select.Fields.Count);
  3522. AssertEquals('One table',1,Select.Tables.Count);
  3523. AssertTable(Select.Tables[0],'A');
  3524. AssertAggregate(Select.Fields[0],afMin,'B',aoNone,'');
  3525. end;
  3526. procedure TTestSelectParser.TestAggregateMinAsterisk;
  3527. begin
  3528. TestSelectError('SELECT Min(*) FROM A');
  3529. end;
  3530. procedure TTestSelectParser.TestAggregateMinAll;
  3531. begin
  3532. TestSelect('SELECT Min(ALL B) FROM A');
  3533. AssertEquals('One field',1,Select.Fields.Count);
  3534. AssertEquals('One table',1,Select.Tables.Count);
  3535. AssertTable(Select.Tables[0],'A');
  3536. AssertAggregate(Select.Fields[0],afMin,'B',aoAll,'');
  3537. end;
  3538. procedure TTestSelectParser.TestAggregateMinDistinct;
  3539. begin
  3540. TestSelect('SELECT Min(DISTINCT B) FROM A');
  3541. AssertEquals('One field',1,Select.Fields.Count);
  3542. AssertEquals('One table',1,Select.Tables.Count);
  3543. AssertTable(Select.Tables[0],'A');
  3544. AssertAggregate(Select.Fields[0],afMin,'B',aoDistinct,'');
  3545. end;
  3546. procedure TTestSelectParser.TestAggregateSum;
  3547. begin
  3548. TestSelect('SELECT Sum(B) FROM A');
  3549. AssertEquals('One field',1,Select.Fields.Count);
  3550. AssertEquals('One table',1,Select.Tables.Count);
  3551. AssertTable(Select.Tables[0],'A');
  3552. AssertAggregate(Select.Fields[0],afSum,'B',aoNone,'');
  3553. end;
  3554. procedure TTestSelectParser.TestAggregateSumAsterisk;
  3555. begin
  3556. TestSelectError('SELECT Sum(*) FROM A');
  3557. end;
  3558. procedure TTestSelectParser.TestAggregateSumAll;
  3559. begin
  3560. TestSelect('SELECT Sum(ALL B) FROM A');
  3561. AssertEquals('One field',1,Select.Fields.Count);
  3562. AssertEquals('One table',1,Select.Tables.Count);
  3563. AssertTable(Select.Tables[0],'A');
  3564. AssertAggregate(Select.Fields[0],afSum,'B',aoAll,'');
  3565. end;
  3566. procedure TTestSelectParser.TestAggregateSumDistinct;
  3567. begin
  3568. TestSelect('SELECT Sum(DISTINCT B) FROM A');
  3569. AssertEquals('One field',1,Select.Fields.Count);
  3570. AssertEquals('One table',1,Select.Tables.Count);
  3571. AssertTable(Select.Tables[0],'A');
  3572. AssertAggregate(Select.Fields[0],afSum,'B',aoDistinct,'');
  3573. end;
  3574. procedure TTestSelectParser.TestAggregateAvg;
  3575. begin
  3576. TestSelect('SELECT Avg(B) FROM A');
  3577. AssertEquals('One field',1,Select.Fields.Count);
  3578. AssertEquals('One table',1,Select.Tables.Count);
  3579. AssertTable(Select.Tables[0],'A');
  3580. AssertAggregate(Select.Fields[0],afAvg,'B',aoNone,'');
  3581. end;
  3582. procedure TTestSelectParser.TestAggregateAvgAsterisk;
  3583. begin
  3584. TestSelectError('SELECT Avg(*) FROM A');
  3585. end;
  3586. procedure TTestSelectParser.TestAggregateAvgAll;
  3587. begin
  3588. TestSelect('SELECT Avg(ALL B) FROM A');
  3589. AssertEquals('One field',1,Select.Fields.Count);
  3590. AssertEquals('One table',1,Select.Tables.Count);
  3591. AssertTable(Select.Tables[0],'A');
  3592. AssertAggregate(Select.Fields[0],afAvg,'B',aoAll,'');
  3593. end;
  3594. procedure TTestSelectParser.TestAggregateAvgDistinct;
  3595. begin
  3596. TestSelect('SELECT Avg(DISTINCT B) FROM A');
  3597. AssertEquals('One field',1,Select.Fields.Count);
  3598. AssertEquals('One table',1,Select.Tables.Count);
  3599. AssertTable(Select.Tables[0],'A');
  3600. AssertAggregate(Select.Fields[0],afAvg,'B',aoDistinct,'');
  3601. end;
  3602. procedure TTestSelectParser.TestUpperConst;
  3603. Var
  3604. E : TSQLFunctionCallExpression;
  3605. L : TSQLLiteralExpression;
  3606. S : TSQLStringLiteral;
  3607. begin
  3608. TestSelect('SELECT UPPER(''a'') FROM A');
  3609. AssertEquals('One field',1,Select.Fields.Count);
  3610. AssertEquals('One table',1,Select.Tables.Count);
  3611. AssertTable(Select.Tables[0],'A');
  3612. CheckClass(Select.Fields[0],TSQLSelectField);
  3613. E:=TSQLFunctionCallExpression(CheckClass(TSQLSelectField(Select.Fields[0]).Expression,TSQLFunctionCallExpression));
  3614. AssertEquals('UPPER function name','UPPER',E.Identifier);
  3615. AssertEquals('One function element',1,E.Arguments.Count);
  3616. L:=TSQLLiteralExpression(CheckClass(E.Arguments[0],TSQLLiteralExpression));
  3617. S:=TSQLStringLiteral(CheckClass(L.Literal,TSQLStringLiteral));
  3618. AssertEquals('Correct constant','a',S.Value);
  3619. end;
  3620. procedure TTestSelectParser.TestUpperError;
  3621. begin
  3622. TestSelectError('SELECT UPPER(''A'',''B'') FROM C');
  3623. end;
  3624. procedure TTestSelectParser.TestGenID;
  3625. Var
  3626. E : TSQLGenIDExpression;
  3627. L : TSQLLiteralExpression;
  3628. S : TSQLIntegerLiteral;
  3629. begin
  3630. TestSelect('SELECT GEN_ID(GEN_B,1) FROM RDB$DATABASE');
  3631. AssertEquals('One field',1,Select.Fields.Count);
  3632. AssertEquals('One table',1,Select.Tables.Count);
  3633. AssertTable(Select.Tables[0],'RDB$DATABASE');
  3634. CheckClass(Select.Fields[0],TSQLSelectField);
  3635. E:=TSQLGenIDExpression(CheckClass(TSQLSelectField(Select.Fields[0]).Expression,TSQLGenIDExpression));
  3636. AssertIdentifierName('GenID generator function name','GEN_B',E.Generator);
  3637. L:=TSQLLiteralExpression(CheckClass(E.Value,TSQLLiteralExpression));
  3638. S:=TSQLIntegerLiteral(CheckClass(L.Literal,TSQLIntegerLiteral));
  3639. AssertEquals('Correct constant',1,S.Value);
  3640. end;
  3641. procedure TTestSelectParser.TestGenIDError1;
  3642. begin
  3643. TestSelectError('SELECT GEN_ID(''GEN_B'',1) FROM RDB$DATABASE');
  3644. end;
  3645. procedure TTestSelectParser.TestGenIDError2;
  3646. begin
  3647. TestSelectError('SELECT GEN_ID(''GEN_B'') FROM RDB$DATABASE');
  3648. end;
  3649. procedure TTestSelectParser.TestCastSimple;
  3650. var
  3651. C : TSQLCastExpression;
  3652. L : TSQLLiteralExpression;
  3653. S : TSQLIntegerLiteral;
  3654. begin
  3655. TestSelect('SELECT CAST(1 AS VARCHAR(5)) FROM A');
  3656. AssertEquals('One field',1,Select.Fields.Count);
  3657. AssertEquals('One table',1,Select.Tables.Count);
  3658. AssertTable(Select.Tables[0],'A');
  3659. CheckClass(Select.Fields[0],TSQLSelectField);
  3660. C:=TSQLCastExpression(CheckClass(TSQLSelectField(Select.Fields[0]).Expression,TSQLCastExpression));
  3661. L:=TSQLLiteralExpression(CheckClass(C.Value,TSQLLiteralExpression));
  3662. S:=TSQLIntegerLiteral(CheckClass(L.Literal,TSQLIntegerLiteral));
  3663. AssertEquals('Correct constant',1,S.Value);
  3664. AssertTypeDefaults(C.NewType,5);
  3665. AssertEquals('Correct type',sdtVarChar,C.NewType.DataType);
  3666. end;
  3667. procedure TTestSelectParser.DoExtractSimple(Expected: TSQLExtractElement);
  3668. var
  3669. E : TSQLExtractExpression;
  3670. I : TSQLIdentifierExpression;
  3671. begin
  3672. TestSelect('SELECT EXTRACT('+ExtractElementNames[Expected]+' FROM B) FROM A');
  3673. AssertEquals('One field',1,Select.Fields.Count);
  3674. AssertEquals('One table',1,Select.Tables.Count);
  3675. AssertTable(Select.Tables[0],'A');
  3676. CheckClass(Select.Fields[0],TSQLSelectField);
  3677. E:=TSQLExtractExpression(CheckClass(TSQLSelectField(Select.Fields[0]).Expression,TSQLExtractExpression));
  3678. I:=TSQLIdentifierExpression(CheckClass(E.Value,TSQLIdentifierExpression));
  3679. AssertIdentifierName('Correct field','B',I.Identifier);
  3680. FreeAndNil(FParser);
  3681. FreeAndNil(FSource);
  3682. FreeAndNil(FToFree);
  3683. end;
  3684. procedure TTestSelectParser.TestExtractSimple;
  3685. Var
  3686. E : TSQLExtractElement;
  3687. begin
  3688. For E:=Low(TSQLExtractElement) to High(TSQLExtractElement) do
  3689. DoExtractSimple(E);
  3690. end;
  3691. procedure TTestSelectParser.TestOrderByOneField;
  3692. begin
  3693. TestSelect('SELECT B FROM A ORDER BY C');
  3694. AssertEquals('One field',1,Select.Fields.Count);
  3695. AssertEquals('One table',1,Select.Tables.Count);
  3696. AssertField(Select.Fields[0],'B');
  3697. AssertTable(Select.Tables[0],'A');
  3698. AssertEquals('One order by field',1,Select.Orderby.Count);
  3699. AssertOrderBy(Select.OrderBy[0],'C',0,obAscending);
  3700. end;
  3701. procedure TTestSelectParser.TestOrderByTwoFields;
  3702. begin
  3703. TestSelect('SELECT B FROM A ORDER BY C,D');
  3704. AssertEquals('One field',1,Select.Fields.Count);
  3705. AssertEquals('One table',1,Select.Tables.Count);
  3706. AssertField(Select.Fields[0],'B');
  3707. AssertTable(Select.Tables[0],'A');
  3708. AssertEquals('Two order by fields',2,Select.Orderby.Count);
  3709. AssertOrderBy(Select.OrderBy[0],'C',0,obAscending);
  3710. AssertOrderBy(Select.OrderBy[1],'D',0,obAscending);
  3711. end;
  3712. procedure TTestSelectParser.TestOrderByThreeFields;
  3713. begin
  3714. TestSelect('SELECT B FROM A ORDER BY C,D,E');
  3715. AssertEquals('One field',1,Select.Fields.Count);
  3716. AssertEquals('One table',1,Select.Tables.Count);
  3717. AssertField(Select.Fields[0],'B');
  3718. AssertTable(Select.Tables[0],'A');
  3719. AssertEquals('Three order by fields',3,Select.Orderby.Count);
  3720. AssertOrderBy(Select.OrderBy[0],'C',0,obAscending);
  3721. AssertOrderBy(Select.OrderBy[1],'D',0,obAscending);
  3722. AssertOrderBy(Select.OrderBy[2],'E',0,obAscending);
  3723. end;
  3724. procedure TTestSelectParser.TestOrderByOneDescField;
  3725. begin
  3726. TestSelect('SELECT B FROM A ORDER BY C DESC');
  3727. AssertEquals('One field',1,Select.Fields.Count);
  3728. AssertEquals('One table',1,Select.Tables.Count);
  3729. AssertField(Select.Fields[0],'B');
  3730. AssertTable(Select.Tables[0],'A');
  3731. AssertEquals('One order by field',1,Select.Orderby.Count);
  3732. AssertOrderBy(Select.OrderBy[0],'C',0,obDescending);
  3733. end;
  3734. procedure TTestSelectParser.TestOrderByTwoDescFields;
  3735. begin
  3736. TestSelect('SELECT B FROM A ORDER BY C DESC, D DESCENDING');
  3737. AssertEquals('One field',1,Select.Fields.Count);
  3738. AssertEquals('One table',1,Select.Tables.Count);
  3739. AssertField(Select.Fields[0],'B');
  3740. AssertTable(Select.Tables[0],'A');
  3741. AssertEquals('Two order by fields',2,Select.Orderby.Count);
  3742. AssertOrderBy(Select.OrderBy[0],'C',0,obDescending);
  3743. AssertOrderBy(Select.OrderBy[1],'D',0,obDescending);
  3744. end;
  3745. procedure TTestSelectParser.TestOrderByThreeDescFields;
  3746. begin
  3747. TestSelect('SELECT B FROM A ORDER BY C DESC,D DESCENDING, E DESC');
  3748. AssertEquals('One field',1,Select.Fields.Count);
  3749. AssertEquals('One table',1,Select.Tables.Count);
  3750. AssertField(Select.Fields[0],'B');
  3751. AssertTable(Select.Tables[0],'A');
  3752. AssertEquals('Three order by fields',3,Select.Orderby.Count);
  3753. AssertOrderBy(Select.OrderBy[0],'C',0,obDescending);
  3754. AssertOrderBy(Select.OrderBy[1],'D',0,obDescending);
  3755. AssertOrderBy(Select.OrderBy[2],'E',0,obDescending);
  3756. end;
  3757. procedure TTestSelectParser.TestOrderByOneTableField;
  3758. begin
  3759. TestSelect('SELECT B FROM A ORDER BY C.D');
  3760. AssertEquals('One field',1,Select.Fields.Count);
  3761. AssertEquals('One table',1,Select.Tables.Count);
  3762. AssertField(Select.Fields[0],'B');
  3763. AssertTable(Select.Tables[0],'A');
  3764. AssertEquals('One order by field',1,Select.Orderby.Count);
  3765. // Field does not support linking/refering to a table, so the field name is
  3766. // assigned as C.D (instead of D with a <link to table C>)
  3767. AssertOrderBy(Select.OrderBy[0],'C.D',0,obAscending);
  3768. end;
  3769. procedure TTestSelectParser.TestOrderByOneColumn;
  3770. begin
  3771. TestSelect('SELECT B FROM A ORDER BY 1');
  3772. AssertEquals('One field',1,Select.Fields.Count);
  3773. AssertEquals('One table',1,Select.Tables.Count);
  3774. AssertField(Select.Fields[0],'B');
  3775. AssertTable(Select.Tables[0],'A');
  3776. AssertEquals('One order by field',1,Select.Orderby.Count);
  3777. AssertOrderBy(Select.OrderBy[0],'',1,obAscending);
  3778. end;
  3779. procedure TTestSelectParser.TestOrderByTwoColumns;
  3780. begin
  3781. TestSelect('SELECT B,C FROM A ORDER BY 1,2');
  3782. AssertEquals('Two fields',2,Select.Fields.Count);
  3783. AssertEquals('One table',1,Select.Tables.Count);
  3784. AssertField(Select.Fields[0],'B');
  3785. AssertField(Select.Fields[1],'C');
  3786. AssertTable(Select.Tables[0],'A');
  3787. AssertEquals('Two order by fields',2,Select.Orderby.Count);
  3788. AssertOrderBy(Select.OrderBy[0],'',1,obAscending);
  3789. AssertOrderBy(Select.OrderBy[1],'',2,obAscending);
  3790. end;
  3791. procedure TTestSelectParser.TestOrderByTwoColumnsDesc;
  3792. begin
  3793. TestSelect('SELECT B,C FROM A ORDER BY 1 DESC,2');
  3794. AssertEquals('Two fields',2,Select.Fields.Count);
  3795. AssertEquals('One table',1,Select.Tables.Count);
  3796. AssertField(Select.Fields[0],'B');
  3797. AssertField(Select.Fields[1],'C');
  3798. AssertTable(Select.Tables[0],'A');
  3799. AssertEquals('Two order by fields',2,Select.Orderby.Count);
  3800. AssertOrderBy(Select.OrderBy[0],'',1,obDescending);
  3801. AssertOrderBy(Select.OrderBy[1],'',2,obAscending);
  3802. end;
  3803. procedure TTestSelectParser.TestOrderByCollate;
  3804. Var
  3805. O : TSQLOrderByElement;
  3806. begin
  3807. TestSelect('SELECT B,C FROM A ORDER BY D COLLATE E');
  3808. AssertEquals('Two fields',2,Select.Fields.Count);
  3809. AssertEquals('One table',1,Select.Tables.Count);
  3810. AssertField(Select.Fields[0],'B');
  3811. AssertField(Select.Fields[1],'C');
  3812. AssertTable(Select.Tables[0],'A');
  3813. AssertEquals('One order by fields',1,Select.Orderby.Count);
  3814. O:=AssertOrderBy(Select.OrderBy[0],'D',0,obAscending);
  3815. AssertIdentifierName('Correct collation','E',O.Collation);
  3816. end;
  3817. procedure TTestSelectParser.TestOrderByCollateDesc;
  3818. Var
  3819. O : TSQLOrderByElement;
  3820. begin
  3821. TestSelect('SELECT B,C FROM A ORDER BY D COLLATE E');
  3822. AssertEquals('Two fields',2,Select.Fields.Count);
  3823. AssertEquals('One table',1,Select.Tables.Count);
  3824. AssertField(Select.Fields[0],'B');
  3825. AssertField(Select.Fields[1],'C');
  3826. AssertTable(Select.Tables[0],'A');
  3827. AssertEquals('One order by fields',1,Select.Orderby.Count);
  3828. O:=AssertOrderBy(Select.OrderBy[0],'D',0,obAscending);
  3829. AssertIdentifierName('Correct collation','E',O.Collation);
  3830. end;
  3831. procedure TTestSelectParser.TestOrderByCollateDescTwoFields;
  3832. Var
  3833. O : TSQLOrderByElement;
  3834. begin
  3835. TestSelect('SELECT B,C FROM A ORDER BY D COLLATE E DESC,F COLLATE E');
  3836. AssertEquals('Two fields',2,Select.Fields.Count);
  3837. AssertEquals('One table',1,Select.Tables.Count);
  3838. AssertField(Select.Fields[0],'B');
  3839. AssertField(Select.Fields[1],'C');
  3840. AssertTable(Select.Tables[0],'A');
  3841. AssertEquals('Two order by fields',2,Select.Orderby.Count);
  3842. O:=AssertOrderBy(Select.OrderBy[0],'D',0,obDescending);
  3843. AssertIdentifierName('Correct collation','E',O.Collation);
  3844. O:=AssertOrderBy(Select.OrderBy[1],'F',0,obAscending);
  3845. AssertIdentifierName('Correct collation','E',O.Collation);
  3846. end;
  3847. procedure TTestSelectParser.TestGroupByOne;
  3848. begin
  3849. TestSelect('SELECT B,COUNT(C) AS THECOUNT FROM A GROUP BY B');
  3850. AssertEquals('Two fields',2,Select.Fields.Count);
  3851. AssertEquals('One group by field',1,Select.GroupBy.Count);
  3852. AssertIdentifierName('Correct group by field','B',Select.GroupBy[0]);
  3853. AssertField(Select.Fields[0],'B');
  3854. AssertAggregate(Select.Fields[1],afCount,'C',aoNone,'THECOUNT');
  3855. end;
  3856. procedure TTestSelectParser.TestGroupByTwo;
  3857. begin
  3858. TestSelect('SELECT B,C,SUM(D) AS THESUM FROM A GROUP BY B,C');
  3859. AssertEquals('Three fields',3,Select.Fields.Count);
  3860. AssertEquals('One group two fields',2,Select.GroupBy.Count);
  3861. AssertIdentifierName('Correct first group by field','B',Select.GroupBy[0]);
  3862. AssertIdentifierName('Correct second group by field','C',Select.GroupBy[1]);
  3863. AssertField(Select.Fields[0],'B');
  3864. AssertField(Select.Fields[1],'C');
  3865. AssertAggregate(Select.Fields[2],afSum,'D',aoNone,'THESUM');
  3866. end;
  3867. procedure TTestSelectParser.TestHavingOne;
  3868. Var
  3869. H : TSQLBinaryExpression;
  3870. L : TSQLLiteralExpression;
  3871. S : TSQLIntegerLiteral;
  3872. begin
  3873. TestSelect('SELECT B,COUNT(C) AS THECOUNT FROM A GROUP BY B HAVING COUNT(C)>1');
  3874. AssertEquals('Two fields',2,Select.Fields.Count);
  3875. AssertEquals('One group by field',1,Select.GroupBy.Count);
  3876. AssertIdentifierName('Correct group by field','B',Select.GroupBy[0]);
  3877. AssertField(Select.Fields[0],'B');
  3878. AssertAggregate(Select.Fields[1],afCount,'C',aoNone,'THECOUNT');
  3879. AssertNotNull('Have having',Select.Having);
  3880. H:=TSQLBinaryExpression(CheckClass(Select.Having,TSQLBinaryExpression));
  3881. AssertEquals('Larger than',boGT,H.Operation);
  3882. L:=TSQLLiteralExpression(CheckClass(H.Right,TSQLLiteralExpression));
  3883. S:=TSQLIntegerLiteral(CheckClass(L.Literal,TSQLIntegerLiteral));
  3884. AssertEquals('One',1,S.Value);
  3885. AssertAggregateExpression(H.Left,afCount,'C',aoNone);
  3886. end;
  3887. procedure TTestSelectParser.TestUnionSimple;
  3888. Var
  3889. S : TSQLSelectStatement;
  3890. begin
  3891. TestSelect('SELECT B FROM A UNION SELECT C FROM D');
  3892. AssertEquals('One field',1,Select.Fields.Count);
  3893. AssertField(Select.Fields[0],'B');
  3894. AssertEquals('One table',1,Select.Tables.Count);
  3895. AssertTable(Select.Tables[0],'A');
  3896. S:=TSQLSelectStatement(CheckClass(Select.Union,TSQLSelectStatement));
  3897. AssertEquals('One field',1,S.Fields.Count);
  3898. AssertField(S.Fields[0],'C');
  3899. AssertEquals('One table',1,S.Tables.Count);
  3900. AssertTable(S.Tables[0],'D');
  3901. AssertEquals('No UNION ALL : ',False,Select.UnionAll)
  3902. end;
  3903. procedure TTestSelectParser.TestUnionSimpleAll;
  3904. Var
  3905. S : TSQLSelectStatement;
  3906. begin
  3907. TestSelect('SELECT B FROM A UNION ALL SELECT C FROM D');
  3908. AssertEquals('One field',1,Select.Fields.Count);
  3909. AssertField(Select.Fields[0],'B');
  3910. AssertEquals('One table',1,Select.Tables.Count);
  3911. AssertTable(Select.Tables[0],'A');
  3912. S:=TSQLSelectStatement(CheckClass(Select.Union,TSQLSelectStatement));
  3913. AssertEquals('One field',1,S.Fields.Count);
  3914. AssertField(S.Fields[0],'C');
  3915. AssertEquals('One table',1,S.Tables.Count);
  3916. AssertTable(S.Tables[0],'D');
  3917. AssertEquals('UNION ALL : ',True,Select.UnionAll)
  3918. end;
  3919. procedure TTestSelectParser.TestUnionSimpleOrderBy;
  3920. Var
  3921. S : TSQLSelectStatement;
  3922. begin
  3923. TestSelect('SELECT B FROM A UNION SELECT C FROM D ORDER BY 1');
  3924. AssertEquals('One field',1,Select.Fields.Count);
  3925. AssertField(Select.Fields[0],'B');
  3926. AssertEquals('One table',1,Select.Tables.Count);
  3927. AssertTable(Select.Tables[0],'A');
  3928. AssertOrderBy(Select.OrderBy[0],'',1,obAscending);
  3929. S:=TSQLSelectStatement(CheckClass(Select.Union,TSQLSelectStatement));
  3930. AssertEquals('One field',1,S.Fields.Count);
  3931. AssertField(S.Fields[0],'C');
  3932. AssertEquals('One table',1,S.Tables.Count);
  3933. AssertTable(S.Tables[0],'D');
  3934. end;
  3935. procedure TTestSelectParser.TestUnionDouble;
  3936. Var
  3937. S : TSQLSelectStatement;
  3938. begin
  3939. TestSelect('SELECT B FROM A UNION SELECT C FROM D UNION SELECT E FROM F ORDER BY 1');
  3940. AssertEquals('One field',1,Select.Fields.Count);
  3941. AssertField(Select.Fields[0],'B');
  3942. AssertEquals('One table',1,Select.Tables.Count);
  3943. AssertTable(Select.Tables[0],'A');
  3944. AssertOrderBy(Select.OrderBy[0],'',1,obAscending);
  3945. S:=TSQLSelectStatement(CheckClass(Select.Union,TSQLSelectStatement));
  3946. AssertEquals('One field',1,S.Fields.Count);
  3947. AssertField(S.Fields[0],'C');
  3948. AssertEquals('One table',1,S.Tables.Count);
  3949. AssertTable(S.Tables[0],'D');
  3950. S:=TSQLSelectStatement(CheckClass(S.Union,TSQLSelectStatement));
  3951. AssertEquals('One field',1,S.Fields.Count);
  3952. AssertField(S.Fields[0],'E');
  3953. AssertEquals('One table',1,S.Tables.Count);
  3954. AssertTable(S.Tables[0],'F');
  3955. end;
  3956. procedure TTestSelectParser.TestUnionError1;
  3957. begin
  3958. TestSelectError('SELECT B FROM A ORDER BY B UNION SELECT C FROM D');
  3959. end;
  3960. procedure TTestSelectParser.TestUnionError2;
  3961. begin
  3962. TestSelectError('SELECT B FROM A UNION SELECT C,E FROM D');
  3963. end;
  3964. procedure TTestSelectParser.TestPlanOrderNatural;
  3965. Var
  3966. E : TSQLSelectPlanExpr;
  3967. N : TSQLSelectNaturalPLan;
  3968. begin
  3969. TestSelect('SELECT A FROM B PLAN SORT (B NATURAL)');
  3970. E:=TSQLSelectPlanExpr(CheckClass(Select.Plan,TSQLSelectPlanExpr));
  3971. AssertEquals('One plan item',1,E.Items.Count);
  3972. AssertEquals('Correct plan type',pjtSort,E.JoinType);
  3973. N:=TSQLSelectNaturalPLan(CheckClass(E.Items[0],TSQLSelectNaturalPLan));
  3974. AssertIdentifierName('Correct table','B',N.TableName);
  3975. end;
  3976. procedure TTestSelectParser.TestPlanOrderOrder;
  3977. Var
  3978. E : TSQLSelectPlanExpr;
  3979. O : TSQLSelectOrderedPLan;
  3980. begin
  3981. TestSelect('SELECT A FROM B PLAN SORT (B ORDER C)');
  3982. E:=TSQLSelectPlanExpr(CheckClass(Select.Plan,TSQLSelectPlanExpr));
  3983. AssertEquals('One plan item',1,E.Items.Count);
  3984. AssertEquals('Correct plan type',pjtSort,E.JoinType);
  3985. O:=TSQLSelectOrderedPLan(CheckClass(E.Items[0],TSQLSelectOrderedPLan));
  3986. AssertIdentifierName('Correct table','B',O.TableName);
  3987. AssertIdentifierName('Correct table','C',O.OrderIndex);
  3988. end;
  3989. procedure TTestSelectParser.TestPlanOrderIndex1;
  3990. Var
  3991. E : TSQLSelectPlanExpr;
  3992. O : TSQLSelectIndexedPLan;
  3993. begin
  3994. TestSelect('SELECT A FROM B PLAN SORT (B INDEX (C))');
  3995. E:=TSQLSelectPlanExpr(CheckClass(Select.Plan,TSQLSelectPlanExpr));
  3996. AssertEquals('One plan item',1,E.Items.Count);
  3997. AssertEquals('Correct plan type',pjtSort,E.JoinType);
  3998. O:=TSQLSelectIndexedPLan(CheckClass(E.Items[0],TSQLSelectIndexedPlan));
  3999. AssertIdentifierName('Correct table','B',O.TableName);
  4000. AssertEquals('Correct index count',1,O.Indexes.Count);
  4001. AssertIdentifierName('Correct table','C',O.Indexes[0]);
  4002. end;
  4003. procedure TTestSelectParser.TestPlanOrderIndex2;
  4004. Var
  4005. E : TSQLSelectPlanExpr;
  4006. O : TSQLSelectIndexedPLan;
  4007. begin
  4008. TestSelect('SELECT A FROM B PLAN SORT (B INDEX (C,D))');
  4009. E:=TSQLSelectPlanExpr(CheckClass(Select.Plan,TSQLSelectPlanExpr));
  4010. AssertEquals('One plan item',1,E.Items.Count);
  4011. AssertEquals('Correct plan type',pjtSort,E.JoinType);
  4012. O:=TSQLSelectIndexedPLan(CheckClass(E.Items[0],TSQLSelectIndexedPlan));
  4013. AssertIdentifierName('Correct table','B',O.TableName);
  4014. AssertEquals('Correct index count',2,O.Indexes.Count);
  4015. AssertIdentifierName('Correct table','C',O.Indexes[0]);
  4016. AssertIdentifierName('Correct table','D',O.Indexes[1]);
  4017. end;
  4018. procedure TTestSelectParser.TestPlanJoinNatural;
  4019. Var
  4020. E : TSQLSelectPlanExpr;
  4021. N : TSQLSelectNaturalPLan;
  4022. O : TSQLSelectOrderedPLan;
  4023. begin
  4024. TestSelect('SELECT A FROM B PLAN JOIN (B NATURAL, C ORDER D)');
  4025. E:=TSQLSelectPlanExpr(CheckClass(Select.Plan,TSQLSelectPlanExpr));
  4026. AssertEquals('One plan item',2,E.Items.Count);
  4027. AssertEquals('Correct plan type',pjtJoin,E.JoinType);
  4028. N:=TSQLSelectNaturalPLan(CheckClass(E.Items[0],TSQLSelectNaturalPlan));
  4029. AssertIdentifierName('Correct table','B',N.TableName);
  4030. O:=TSQLSelectOrderedPLan(CheckClass(E.Items[1],TSQLSelectOrderedPlan));
  4031. AssertIdentifierName('Correct table','C',O.TableName);
  4032. AssertIdentifierName('Correct index','D',O.OrderIndex);
  4033. end;
  4034. procedure TTestSelectParser.TestPlanDefaultNatural;
  4035. Var
  4036. E : TSQLSelectPlanExpr;
  4037. N : TSQLSelectNaturalPLan;
  4038. O : TSQLSelectOrderedPLan;
  4039. begin
  4040. TestSelect('SELECT A FROM B PLAN (B NATURAL, C ORDER D)');
  4041. E:=TSQLSelectPlanExpr(CheckClass(Select.Plan,TSQLSelectPlanExpr));
  4042. AssertEquals('One plan item',2,E.Items.Count);
  4043. AssertEquals('Correct plan type',pjtJoin,E.JoinType);
  4044. N:=TSQLSelectNaturalPLan(CheckClass(E.Items[0],TSQLSelectNaturalPlan));
  4045. AssertIdentifierName('Correct table','B',N.TableName);
  4046. O:=TSQLSelectOrderedPLan(CheckClass(E.Items[1],TSQLSelectOrderedPlan));
  4047. AssertIdentifierName('Correct table','C',O.TableName);
  4048. AssertIdentifierName('Correct index','D',O.OrderIndex);
  4049. end;
  4050. procedure TTestSelectParser.TestPlanMergeNatural;
  4051. Var
  4052. E : TSQLSelectPlanExpr;
  4053. N : TSQLSelectNaturalPLan;
  4054. O : TSQLSelectOrderedPLan;
  4055. begin
  4056. TestSelect('SELECT A FROM B PLAN MERGE (B NATURAL, C ORDER D)');
  4057. E:=TSQLSelectPlanExpr(CheckClass(Select.Plan,TSQLSelectPlanExpr));
  4058. AssertEquals('One plan item',2,E.Items.Count);
  4059. AssertEquals('Correct plan type',pjtMerge,E.JoinType);
  4060. N:=TSQLSelectNaturalPLan(CheckClass(E.Items[0],TSQLSelectNaturalPlan));
  4061. AssertIdentifierName('Correct table','B',N.TableName);
  4062. O:=TSQLSelectOrderedPLan(CheckClass(E.Items[1],TSQLSelectOrderedPlan));
  4063. AssertIdentifierName('Correct table','C',O.TableName);
  4064. AssertIdentifierName('Correct index','D',O.OrderIndex);
  4065. end;
  4066. procedure TTestSelectParser.TestPlanMergeNested;
  4067. Var
  4068. E,EN : TSQLSelectPlanExpr;
  4069. N : TSQLSelectNaturalPLan;
  4070. I : TSQLSelectIndexedPLan;
  4071. begin
  4072. TestSelect('SELECT A FROM B PLAN MERGE (SORT (B NATURAL), SORT (JOIN (D NATURAL, E INDEX (F))))');
  4073. E:=TSQLSelectPlanExpr(CheckClass(Select.Plan,TSQLSelectPlanExpr));
  4074. AssertEquals('Two plan items',2,E.Items.Count);
  4075. AssertEquals('Correct overall plan type',pjtMerge,E.JoinType);
  4076. // SORT (B NATURAL)
  4077. EN:=TSQLSelectPlanExpr(CheckClass(E.Items[0],TSQLSelectPlanExpr));
  4078. AssertEquals('Correct plan type Item 1',pjtSort,EN.JoinType);
  4079. AssertEquals('On plan item in item 1',1,EN.Items.Count);
  4080. N:=TSQLSelectNaturalPLan(CheckClass(EN.Items[0],TSQLSelectNaturalPlan));
  4081. AssertIdentifierName('Correct table','B',N.TableName);
  4082. // SORT (JOIN (D...
  4083. EN:=TSQLSelectPlanExpr(CheckClass(E.Items[1],TSQLSelectPlanExpr));
  4084. AssertEquals('Correct plan type item 2',pjtSort,EN.JoinType);
  4085. AssertEquals('One plan item in item 2',1,EN.Items.Count);
  4086. // JOIN (D NATURAL, E
  4087. E:=TSQLSelectPlanExpr(CheckClass(EN.Items[0],TSQLSelectPlanExpr));
  4088. AssertEquals('Correct plan type',pjtJoin,E.JoinType);
  4089. AssertEquals('Two plan items in item 2',2,E.Items.Count);
  4090. N:=TSQLSelectNaturalPLan(CheckClass(E.Items[0],TSQLSelectNaturalPlan));
  4091. AssertIdentifierName('Correct table','D',N.TableName);
  4092. // E INDEX (F)
  4093. I:=TSQLSelectIndexedPLan(CheckClass(E.Items[1],TSQLSelectIndexedPlan));
  4094. AssertIdentifierName('Correct table','E',I.TableName);
  4095. AssertEquals('Correct index count for table E',1,I.Indexes.Count);
  4096. AssertIdentifierName('Correct index for table E','F',I.Indexes[0]);
  4097. end;
  4098. procedure TTestSelectParser.TestSubSelect;
  4099. Var
  4100. F : TSQLSelectField;
  4101. E : TSQLSelectExpression;
  4102. S : TSQLSelectStatement;
  4103. begin
  4104. TestSelect('SELECT A,(SELECT C FROM D WHERE E=A) AS THECOUNT FROM B');
  4105. AssertEquals('1 table in select',1,Select.Tables.Count);
  4106. AssertTable(Select.Tables[0],'B','');
  4107. AssertEquals('2 fields in select',2,Select.Fields.Count);
  4108. AssertField(Select.Fields[0],'A','');
  4109. F:=TSQLSelectField(CheckClass(Select.fields[1],TSQLSelectField));
  4110. AssertIdentifierName('Correct alias name for subselect','THECOUNT',F.AliasName);
  4111. E:=TSQLSelectExpression(CheckClass(F.Expression,TSQLSelectExpression));
  4112. S:=TSQLSelectStatement(CheckClass(E.Select,TSQLSelectStatement));
  4113. AssertEquals('1 field in subselect',1,S.Fields.Count);
  4114. AssertField(S.Fields[0],'C','');
  4115. AssertEquals('1 table in subselect',1,S.Tables.Count);
  4116. AssertTable(S.Tables[0],'D','');
  4117. end;
  4118. procedure TTestSelectParser.TestWhereExists;
  4119. Var
  4120. F : TSQLSelectField;
  4121. E : TSQLExistsExpression;
  4122. S : TSQLSelectStatement;
  4123. begin
  4124. TestSelect('SELECT A FROM B WHERE EXISTS (SELECT C FROM D WHERE E=A)');
  4125. AssertEquals('1 table in select',1,Select.Tables.Count);
  4126. AssertTable(Select.Tables[0],'B','');
  4127. AssertEquals('1 fields in select',1,Select.Fields.Count);
  4128. AssertField(Select.Fields[0],'A','');
  4129. E:=TSQLExistsExpression(CheckClass(Select.Where,TSQLExistsExpression));
  4130. S:=TSQLSelectStatement(CheckClass(E.Select,TSQLSelectStatement));
  4131. AssertEquals('1 field in subselect',1,S.Fields.Count);
  4132. AssertField(S.Fields[0],'C','');
  4133. AssertEquals('1 table in subselect',1,S.Tables.Count);
  4134. AssertTable(S.Tables[0],'D','');
  4135. end;
  4136. procedure TTestSelectParser.TestWhereSingular;
  4137. Var
  4138. E : TSQLSingularExpression;
  4139. S : TSQLSelectStatement;
  4140. begin
  4141. TestSelect('SELECT A FROM B WHERE SINGULAR (SELECT C FROM D WHERE E=A)');
  4142. AssertEquals('1 table in select',1,Select.Tables.Count);
  4143. AssertTable(Select.Tables[0],'B','');
  4144. AssertEquals('1 fields in select',1,Select.Fields.Count);
  4145. AssertField(Select.Fields[0],'A','');
  4146. E:=TSQLSingularExpression(CheckClass(Select.Where,TSQLSingularExpression));
  4147. S:=TSQLSelectStatement(CheckClass(E.Select,TSQLSelectStatement));
  4148. AssertEquals('1 field in subselect',1,S.Fields.Count);
  4149. AssertField(S.Fields[0],'C','');
  4150. AssertEquals('1 table in subselect',1,S.Tables.Count);
  4151. AssertTable(S.Tables[0],'D','');
  4152. end;
  4153. procedure TTestSelectParser.TestWhereAll;
  4154. Var
  4155. E : TSQLAllExpression;
  4156. S : TSQLSelectStatement;
  4157. B : TSQLBinaryExpression;
  4158. begin
  4159. TestSelect('SELECT A FROM B WHERE A > ALL (SELECT C FROM D WHERE E=F)');
  4160. AssertEquals('1 table in select',1,Select.Tables.Count);
  4161. AssertTable(Select.Tables[0],'B','');
  4162. AssertEquals('1 fields in select',1,Select.Fields.Count);
  4163. AssertField(Select.Fields[0],'A','');
  4164. B:=TSQLBinaryExpression(CheckClass(Select.Where,TSQLBinaryExpression));
  4165. AssertEquals('Correct operation',boGT,B.Operation);
  4166. E:=TSQLAllExpression(CheckClass(B.right,TSQLAllExpression));
  4167. S:=TSQLSelectStatement(CheckClass(E.Select,TSQLSelectStatement));
  4168. AssertEquals('1 field in subselect',1,S.Fields.Count);
  4169. AssertField(S.Fields[0],'C','');
  4170. AssertEquals('1 table in subselect',1,S.Tables.Count);
  4171. AssertTable(S.Tables[0],'D','');
  4172. end;
  4173. procedure TTestSelectParser.TestWhereAny;
  4174. Var
  4175. E : TSQLANyExpression;
  4176. S : TSQLSelectStatement;
  4177. B : TSQLBinaryExpression;
  4178. begin
  4179. TestSelect('SELECT A FROM B WHERE A > ANY (SELECT C FROM D WHERE E=F)');
  4180. AssertEquals('1 table in select',1,Select.Tables.Count);
  4181. AssertTable(Select.Tables[0],'B','');
  4182. AssertEquals('1 fields in select',1,Select.Fields.Count);
  4183. AssertField(Select.Fields[0],'A','');
  4184. B:=TSQLBinaryExpression(CheckClass(Select.Where,TSQLBinaryExpression));
  4185. AssertEquals('Correct operation',boGT,B.Operation);
  4186. E:=TSQLAnyExpression(CheckClass(B.right,TSQLANyExpression));
  4187. S:=TSQLSelectStatement(CheckClass(E.Select,TSQLSelectStatement));
  4188. AssertEquals('1 field in subselect',1,S.Fields.Count);
  4189. AssertField(S.Fields[0],'C','');
  4190. AssertEquals('1 table in subselect',1,S.Tables.Count);
  4191. AssertTable(S.Tables[0],'D','');
  4192. end;
  4193. procedure TTestSelectParser.TestWhereSome;
  4194. Var
  4195. E : TSQLSomeExpression;
  4196. S : TSQLSelectStatement;
  4197. B : TSQLBinaryExpression;
  4198. begin
  4199. TestSelect('SELECT A FROM B WHERE A > SOME (SELECT C FROM D WHERE E=F)');
  4200. AssertEquals('1 table in select',1,Select.Tables.Count);
  4201. AssertTable(Select.Tables[0],'B','');
  4202. AssertEquals('1 fields in select',1,Select.Fields.Count);
  4203. AssertField(Select.Fields[0],'A','');
  4204. B:=TSQLBinaryExpression(CheckClass(Select.Where,TSQLBinaryExpression));
  4205. AssertEquals('Correct operation',boGT,B.Operation);
  4206. E:=TSQLSomeExpression(CheckClass(B.right,TSQLSomeExpression));
  4207. S:=TSQLSelectStatement(CheckClass(E.Select,TSQLSelectStatement));
  4208. AssertEquals('1 field in subselect',1,S.Fields.Count);
  4209. AssertField(S.Fields[0],'C','');
  4210. AssertEquals('1 table in subselect',1,S.Tables.Count);
  4211. AssertTable(S.Tables[0],'D','');
  4212. end;
  4213. procedure TTestSelectParser.TestParam;
  4214. Var
  4215. F : TSQLSelectField;
  4216. P : TSQLParameterExpression;
  4217. begin
  4218. TestSelect('SELECT :A FROM B');
  4219. AssertEquals('1 table in select',1,Select.Tables.Count);
  4220. AssertTable(Select.Tables[0],'B','');
  4221. AssertEquals('1 fields in select',1,Select.Fields.Count);
  4222. AssertNotNull('Have field',Select.Fields[0]);
  4223. F:=TSQLSelectField(CheckClass(Select.Fields[0],TSQLSelectField));
  4224. AssertNotNull('Have field expresssion,',F.Expression);
  4225. P:=TSQLParameterExpression(CheckClass(F.Expression,TSQLParameterExpression));
  4226. AssertIdentifierName('Correct parameter name','A',P.Identifier);
  4227. end;
  4228. procedure TTestSelectParser.TestParamExpr;
  4229. Var
  4230. F : TSQLSelectField;
  4231. P : TSQLParameterExpression;
  4232. B : TSQLBinaryExpression;
  4233. begin
  4234. TestSelect('SELECT :A + 1 FROM B');
  4235. AssertEquals('1 table in select',1,Select.Tables.Count);
  4236. AssertTable(Select.Tables[0],'B','');
  4237. AssertEquals('1 fields in select',1,Select.Fields.Count);
  4238. AssertNotNull('Have field',Select.Fields[0]);
  4239. F:=TSQLSelectField(CheckClass(Select.Fields[0],TSQLSelectField));
  4240. AssertNotNull('Have field expresssion,',F.Expression);
  4241. B:=TSQLBinaryExpression(CheckClass(F.Expression,TSQLBinaryExpression));
  4242. P:=TSQLParameterExpression(CheckClass(B.Left,TSQLParameterExpression));
  4243. AssertIdentifierName('Correct parameter name','A',P.Identifier);
  4244. end;
  4245. { TTestRollBackParser }
  4246. function TTestRollBackParser.TestRollback(const ASource: String
  4247. ): TSQLRollbackStatement;
  4248. begin
  4249. CreateParser(ASource);
  4250. FToFree:=Parser.Parse;
  4251. Result:=TSQLRollbackStatement(CheckClass(FToFree,TSQLRollbackStatement));
  4252. FRollback:=Result;
  4253. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  4254. end;
  4255. procedure TTestRollBackParser.TestRollbackError(const ASource: String);
  4256. begin
  4257. FErrSource:=ASource;
  4258. AssertException(ESQLParser,@TestParseError);
  4259. end;
  4260. procedure TTestRollBackParser.TestRollback;
  4261. begin
  4262. TestRollBack('ROLLBACK');
  4263. AssertNull('No transaction name',Rollback.TransactionName);
  4264. AssertEquals('No work',False,Rollback.Work);
  4265. AssertEquals('No release',False,Rollback.Release);
  4266. end;
  4267. procedure TTestRollBackParser.TestRollbackWork;
  4268. begin
  4269. TestRollBack('ROLLBACK WORK');
  4270. AssertNull('No transaction name',Rollback.TransactionName);
  4271. AssertEquals('work',True,Rollback.Work);
  4272. AssertEquals('No release',False,Rollback.Release);
  4273. end;
  4274. procedure TTestRollBackParser.TestRollbackRelease;
  4275. begin
  4276. TestRollBack('ROLLBACK RELEASE');
  4277. AssertNull('No transaction name',Rollback.TransactionName);
  4278. AssertEquals('no work',False,Rollback.Work);
  4279. AssertEquals('release',True,Rollback.Release);
  4280. end;
  4281. procedure TTestRollBackParser.TestRollbackWorkRelease;
  4282. begin
  4283. TestRollBack('ROLLBACK WORK RELEASE');
  4284. AssertNull('No transaction name',Rollback.TransactionName);
  4285. AssertEquals('work',True,Rollback.Work);
  4286. AssertEquals('release',True,Rollback.Release);
  4287. end;
  4288. procedure TTestRollBackParser.TestRollbackTransaction;
  4289. begin
  4290. TestRollBack('ROLLBACK TRANSACTION T');
  4291. AssertIdentifierName('Transaction name','T',Rollback.TransactionName);
  4292. AssertEquals('No work',False,Rollback.Work);
  4293. AssertEquals('No release',False,Rollback.Release);
  4294. end;
  4295. procedure TTestRollBackParser.TestRollbackTransactionWork;
  4296. begin
  4297. TestRollBack('ROLLBACK TRANSACTION T WORK');
  4298. AssertIdentifierName('Transaction name','T',Rollback.TransactionName);
  4299. AssertEquals('work',True,Rollback.Work);
  4300. AssertEquals('No release',False,Rollback.Release);
  4301. end;
  4302. procedure TTestRollBackParser.TestRollbackTransactionRelease;
  4303. begin
  4304. TestRollBack('ROLLBACK TRANSACTION T RELEASE');
  4305. AssertIdentifierName('Transaction name','T',Rollback.TransactionName);
  4306. AssertEquals('no work',False,Rollback.Work);
  4307. AssertEquals('release',True,Rollback.Release);
  4308. end;
  4309. procedure TTestRollBackParser.TestRollbackTransactionWorkRelease;
  4310. begin
  4311. TestRollBack('ROLLBACK TRANSACTION T WORK RELEASE');
  4312. AssertIdentifierName('Transaction name','T',Rollback.TransactionName);
  4313. AssertEquals('work',True,Rollback.Work);
  4314. AssertEquals('release',True,Rollback.Release);
  4315. end;
  4316. { TTestCommitParser }
  4317. function TTestCommitParser.TestCommit(const ASource: String
  4318. ): TSQLCommitStatement;
  4319. begin
  4320. CreateParser(ASource);
  4321. FToFree:=Parser.Parse;
  4322. Result:=TSQLCommitStatement(CheckClass(FToFree,TSQLCommitStatement));
  4323. FCommit:=Result;
  4324. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  4325. end;
  4326. procedure TTestCommitParser.TestCommitError(const ASource: String);
  4327. begin
  4328. FErrSource:=ASource;
  4329. AssertException(ESQLParser,@TestParseError);
  4330. end;
  4331. procedure TTestCommitParser.TestCommit;
  4332. begin
  4333. TestCommit('Commit');
  4334. AssertNull('No transaction name',Commit.TransactionName);
  4335. AssertEquals('No work',False,Commit.Work);
  4336. AssertEquals('No release',False,Commit.Release);
  4337. AssertEquals('No Retain',False,Commit.Retain);
  4338. end;
  4339. procedure TTestCommitParser.TestCommitWork;
  4340. begin
  4341. TestCommit('Commit WORK');
  4342. AssertNull('No transaction name',Commit.TransactionName);
  4343. AssertEquals('work',True,Commit.Work);
  4344. AssertEquals('No release',False,Commit.Release);
  4345. AssertEquals('No Retain',False,Commit.Retain);
  4346. end;
  4347. procedure TTestCommitParser.TestCommitRelease;
  4348. begin
  4349. TestCommit('Commit RELEASE');
  4350. AssertNull('No transaction name',Commit.TransactionName);
  4351. AssertEquals('no work',False,Commit.Work);
  4352. AssertEquals('release',True,Commit.Release);
  4353. AssertEquals('No Retain',False,Commit.Retain);
  4354. end;
  4355. procedure TTestCommitParser.TestCommitWorkRelease;
  4356. begin
  4357. TestCommit('Commit WORK RELEASE');
  4358. AssertNull('No transaction name',Commit.TransactionName);
  4359. AssertEquals('work',True,Commit.Work);
  4360. AssertEquals('release',True,Commit.Release);
  4361. AssertEquals('No Retain',False,Commit.Retain);
  4362. end;
  4363. procedure TTestCommitParser.TestCommitTransaction;
  4364. begin
  4365. TestCommit('Commit TRANSACTION T');
  4366. AssertIdentifierName('Transaction name','T',Commit.TransactionName);
  4367. AssertEquals('No work',False,Commit.Work);
  4368. AssertEquals('No release',False,Commit.Release);
  4369. AssertEquals('No Retain',False,Commit.Retain);
  4370. end;
  4371. procedure TTestCommitParser.TestCommitTransactionWork;
  4372. begin
  4373. TestCommit('Commit WORK TRANSACTION T ');
  4374. AssertIdentifierName('Transaction name','T',Commit.TransactionName);
  4375. AssertEquals('work',True,Commit.Work);
  4376. AssertEquals('No release',False,Commit.Release);
  4377. AssertEquals('No Retain',False,Commit.Retain);
  4378. end;
  4379. procedure TTestCommitParser.TestCommitTransactionRelease;
  4380. begin
  4381. TestCommit('Commit TRANSACTION T RELEASE');
  4382. AssertIdentifierName('Transaction name','T',Commit.TransactionName);
  4383. AssertEquals('no work',False,Commit.Work);
  4384. AssertEquals('release',True,Commit.Release);
  4385. AssertEquals('No Retain',False,Commit.Retain);
  4386. end;
  4387. procedure TTestCommitParser.TestCommitTransactionWorkRelease;
  4388. begin
  4389. TestCommit('Commit WORK TRANSACTION T RELEASE');
  4390. AssertIdentifierName('Transaction name','T',Commit.TransactionName);
  4391. AssertEquals('work',True,Commit.Work);
  4392. AssertEquals('release',True,Commit.Release);
  4393. AssertEquals('No Retain',False,Commit.Retain);
  4394. end;
  4395. procedure TTestCommitParser.TestCommitRetain;
  4396. begin
  4397. TestCommit('Commit RETAIN');
  4398. AssertNull('No transaction name',Commit.TransactionName);
  4399. AssertEquals('No work',False,Commit.Work);
  4400. AssertEquals('No release',False,Commit.Release);
  4401. AssertEquals('Retain',True,Commit.Retain);
  4402. end;
  4403. procedure TTestCommitParser.TestCommitRetainSnapShot;
  4404. begin
  4405. TestCommit('Commit RETAIN SNAPSHOT');
  4406. AssertNull('No transaction name',Commit.TransactionName);
  4407. AssertEquals('No work',False,Commit.Work);
  4408. AssertEquals('No release',False,Commit.Release);
  4409. AssertEquals('Retain',True,Commit.Retain);
  4410. end;
  4411. procedure TTestCommitParser.TestCommitWorkRetain;
  4412. begin
  4413. TestCommit('Commit WORK RETAIN');
  4414. AssertNull('No transaction name',Commit.TransactionName);
  4415. AssertEquals('work',True,Commit.Work);
  4416. AssertEquals('No release',False,Commit.Release);
  4417. AssertEquals('Retain',True,Commit.Retain);
  4418. end;
  4419. procedure TTestCommitParser.TestCommitReleaseRetain;
  4420. begin
  4421. TestCommit('Commit RELEASE RETAIN');
  4422. AssertNull('No transaction name',Commit.TransactionName);
  4423. AssertEquals('no work',False,Commit.Work);
  4424. AssertEquals('release',True,Commit.Release);
  4425. AssertEquals('Retain',True,Commit.Retain);
  4426. end;
  4427. procedure TTestCommitParser.TestCommitWorkReleaseRetain;
  4428. begin
  4429. TestCommit('Commit WORK RELEASE RETAIN');
  4430. AssertNull('No transaction name',Commit.TransactionName);
  4431. AssertEquals('work',True,Commit.Work);
  4432. AssertEquals('release',True,Commit.Release);
  4433. AssertEquals('Retain',True,Commit.Retain);
  4434. end;
  4435. procedure TTestCommitParser.TestCommitTransactionRetain;
  4436. begin
  4437. TestCommit('Commit TRANSACTION T RETAIN');
  4438. AssertIdentifierName('Transaction name','T',Commit.TransactionName);
  4439. AssertEquals('No work',False,Commit.Work);
  4440. AssertEquals('No release',False,Commit.Release);
  4441. AssertEquals('Retain',True,Commit.Retain);
  4442. end;
  4443. procedure TTestCommitParser.TestCommitTransactionWorkRetain;
  4444. begin
  4445. TestCommit('Commit WORK TRANSACTION T RETAIN');
  4446. AssertIdentifierName('Transaction name','T',Commit.TransactionName);
  4447. AssertEquals('work',True,Commit.Work);
  4448. AssertEquals('No release',False,Commit.Release);
  4449. AssertEquals('Retain',True,Commit.Retain);
  4450. end;
  4451. procedure TTestCommitParser.TestCommitTransactionReleaseRetain;
  4452. begin
  4453. TestCommit('Commit TRANSACTION T RELEASE RETAIN');
  4454. AssertIdentifierName('Transaction name','T',Commit.TransactionName);
  4455. AssertEquals('no work',False,Commit.Work);
  4456. AssertEquals('release',True,Commit.Release);
  4457. AssertEquals('Retain',True,Commit.Retain);
  4458. end;
  4459. procedure TTestCommitParser.TestCommitTransactionWorkReleaseRetain;
  4460. begin
  4461. TestCommit('Commit WORK TRANSACTION T RELEASE RETAIN');
  4462. AssertIdentifierName('Transaction name','T',Commit.TransactionName);
  4463. AssertEquals('work',True,Commit.Work);
  4464. AssertEquals('release',True,Commit.Release);
  4465. AssertEquals('Retain',True,Commit.Retain);
  4466. end;
  4467. { TTestExecuteProcedureParser }
  4468. function TTestExecuteProcedureParser.TestExecute(const ASource: String
  4469. ): TSQLExecuteProcedureStatement;
  4470. begin
  4471. CreateParser(ASource);
  4472. FToFree:=Parser.Parse;
  4473. Result:=TSQLExecuteProcedureStatement(CheckClass(FToFree,TSQLExecuteProcedureStatement));
  4474. FExecute:=Result;
  4475. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  4476. end;
  4477. procedure TTestExecuteProcedureParser.TestExecuteError(const ASource: String);
  4478. begin
  4479. FErrSource:=ASource;
  4480. AssertException(ESQLParser,@TestParseError);
  4481. end;
  4482. procedure TTestExecuteProcedureParser.TestExecuteSimple;
  4483. begin
  4484. TestExecute('EXECUTE PROCEDURE A');
  4485. AssertIdentifierName('Correct procedure name','A',Execute.ProcedureName);
  4486. AssertNull('No transaction name',Execute.TransactionName);
  4487. AssertEquals('No arguments',0,Execute.Params.Count);
  4488. AssertEquals('No return values',0,Execute.Returning.Count);
  4489. end;
  4490. procedure TTestExecuteProcedureParser.TestExecuteSimpleTransaction;
  4491. begin
  4492. TestExecute('EXECUTE PROCEDURE TRANSACTION B A');
  4493. AssertIdentifierName('Correct procedure name','A',Execute.ProcedureName);
  4494. AssertIdentifierName('Correct transaction name','B',Execute.TransactionName);
  4495. AssertEquals('No arguments',0,Execute.Params.Count);
  4496. AssertEquals('No return values',0,Execute.Returning.Count);
  4497. end;
  4498. procedure TTestExecuteProcedureParser.TestExecuteSimpleReturningValues;
  4499. begin
  4500. TestExecute('EXECUTE PROCEDURE A RETURNING_VALUES :B');
  4501. AssertIdentifierName('Correct procedure name','A',Execute.ProcedureName);
  4502. AssertNull('No transaction name',Execute.TransactionName);
  4503. AssertEquals('No arguments',0,Execute.Params.Count);
  4504. AssertEquals('1 return value',1,Execute.Returning.Count);
  4505. AssertIdentifierName('return value','B',Execute.Returning[0]);
  4506. end;
  4507. procedure TTestExecuteProcedureParser.TestExecuteSimpleReturning2Values;
  4508. begin
  4509. TestExecute('EXECUTE PROCEDURE A RETURNING_VALUES :B,:C');
  4510. AssertIdentifierName('Correct procedure name','A',Execute.ProcedureName);
  4511. AssertNull('No transaction name',Execute.TransactionName);
  4512. AssertEquals('No arguments',0,Execute.Params.Count);
  4513. AssertEquals('2 return values',2,Execute.Returning.Count);
  4514. AssertIdentifierName('return value','B',Execute.Returning[0]);
  4515. AssertIdentifierName('return value','C',Execute.Returning[1]);
  4516. end;
  4517. procedure TTestExecuteProcedureParser.TestExecuteOneArg;
  4518. Var
  4519. I : TSQLIdentifierExpression;
  4520. begin
  4521. TestExecute('EXECUTE PROCEDURE A (B)');
  4522. AssertIdentifierName('Correct procedure name','A',Execute.ProcedureName);
  4523. AssertNull('No transaction name',Execute.TransactionName);
  4524. AssertEquals('One argument',1,Execute.Params.Count);
  4525. I:=TSQLIdentifierExpression(CheckClass(Execute.Params[0],TSQLIdentifierExpression));
  4526. AssertIdentifierName('Correct argument','B',I.Identifier);
  4527. AssertEquals('No return values',0,Execute.Returning.Count);
  4528. end;
  4529. procedure TTestExecuteProcedureParser.TestExecuteOneArgNB;
  4530. Var
  4531. I : TSQLIdentifierExpression;
  4532. begin
  4533. TestExecute('EXECUTE PROCEDURE A B');
  4534. AssertIdentifierName('Correct procedure name','A',Execute.ProcedureName);
  4535. AssertNull('No transaction name',Execute.TransactionName);
  4536. AssertEquals('One argument',1,Execute.Params.Count);
  4537. I:=TSQLIdentifierExpression(CheckClass(Execute.Params[0],TSQLIdentifierExpression));
  4538. AssertIdentifierName('Correct argument','B',I.Identifier);
  4539. AssertEquals('No return values',0,Execute.Returning.Count);
  4540. end;
  4541. procedure TTestExecuteProcedureParser.TestExecuteTwoArgs;
  4542. Var
  4543. I : TSQLIdentifierExpression;
  4544. begin
  4545. TestExecute('EXECUTE PROCEDURE A (B,C)');
  4546. AssertIdentifierName('Correct procedure name','A',Execute.ProcedureName);
  4547. AssertNull('No transaction name',Execute.TransactionName);
  4548. AssertEquals('Two arguments',2,Execute.Params.Count);
  4549. I:=TSQLIdentifierExpression(CheckClass(Execute.Params[0],TSQLIdentifierExpression));
  4550. AssertIdentifierName('Correct argument','B',I.Identifier);
  4551. I:=TSQLIdentifierExpression(CheckClass(Execute.Params[1],TSQLIdentifierExpression));
  4552. AssertIdentifierName('Correct argument','C',I.Identifier);
  4553. AssertEquals('No return values',0,Execute.Returning.Count);
  4554. end;
  4555. procedure TTestExecuteProcedureParser.TestExecuteTwoArgsNB;
  4556. Var
  4557. I : TSQLIdentifierExpression;
  4558. begin
  4559. TestExecute('EXECUTE PROCEDURE A B, C');
  4560. AssertIdentifierName('Correct procedure name','A',Execute.ProcedureName);
  4561. AssertNull('No transaction name',Execute.TransactionName);
  4562. AssertEquals('Two arguments',2,Execute.Params.Count);
  4563. I:=TSQLIdentifierExpression(CheckClass(Execute.Params[0],TSQLIdentifierExpression));
  4564. AssertIdentifierName('Correct argument','B',I.Identifier);
  4565. I:=TSQLIdentifierExpression(CheckClass(Execute.Params[1],TSQLIdentifierExpression));
  4566. AssertIdentifierName('Correct argument','C',I.Identifier);
  4567. AssertEquals('No return values',0,Execute.Returning.Count);
  4568. end;
  4569. procedure TTestExecuteProcedureParser.TestExecuteOneArgSelect;
  4570. Var
  4571. S : TSQLSelectExpression;
  4572. begin
  4573. TestExecute('EXECUTE PROCEDURE A ((SELECT B FROM C))');
  4574. AssertIdentifierName('Correct procedure name','A',Execute.ProcedureName);
  4575. AssertNull('No transaction name',Execute.TransactionName);
  4576. AssertEquals('One argument',1,Execute.Params.Count);
  4577. S:=TSQLSelectExpression(CheckClass(Execute.Params[0],TSQLSelectExpression));
  4578. AssertField(S.Select.Fields[0],'B','');
  4579. AssertTable(S.Select.Tables[0],'C','');
  4580. AssertEquals('No return values',0,Execute.Returning.Count);
  4581. end;
  4582. procedure TTestExecuteProcedureParser.TestExecuteOneArgSelectNB;
  4583. Var
  4584. S : TSQLSelectExpression;
  4585. begin
  4586. TestExecute('EXECUTE PROCEDURE A (SELECT B FROM C)');
  4587. AssertIdentifierName('Correct procedure name','A',Execute.ProcedureName);
  4588. AssertNull('No transaction name',Execute.TransactionName);
  4589. AssertEquals('One argument',1,Execute.Params.Count);
  4590. S:=TSQLSelectExpression(CheckClass(Execute.Params[0],TSQLSelectExpression));
  4591. AssertField(S.Select.Fields[0],'B','');
  4592. AssertTable(S.Select.Tables[0],'C','');
  4593. AssertEquals('No return values',0,Execute.Returning.Count);
  4594. end;
  4595. procedure TTestExecuteProcedureParser.TestExecuteTwoArgsSelect;
  4596. Var
  4597. S : TSQLSelectExpression;
  4598. I : TSQLIdentifierExpression;
  4599. begin
  4600. TestExecute('EXECUTE PROCEDURE A ((SELECT B FROM C),D)');
  4601. AssertIdentifierName('Correct procedure name','A',Execute.ProcedureName);
  4602. AssertNull('No transaction name',Execute.TransactionName);
  4603. AssertEquals('Two arguments',2,Execute.Params.Count);
  4604. S:=TSQLSelectExpression(CheckClass(Execute.Params[0],TSQLSelectExpression));
  4605. AssertField(S.Select.Fields[0],'B','');
  4606. AssertTable(S.Select.Tables[0],'C','');
  4607. I:=TSQLIdentifierExpression(CheckClass(Execute.Params[1],TSQLIdentifierExpression));
  4608. AssertIdentifierName('Correct argument','D',I.Identifier);
  4609. AssertEquals('No return values',0,Execute.Returning.Count);
  4610. end;
  4611. procedure TTestExecuteProcedureParser.TestExecuteTwoArgsSelectNB;
  4612. Var
  4613. S : TSQLSelectExpression;
  4614. I : TSQLIdentifierExpression;
  4615. begin
  4616. TestExecute('EXECUTE PROCEDURE A (SELECT B FROM C),D');
  4617. AssertIdentifierName('Correct procedure name','A',Execute.ProcedureName);
  4618. AssertNull('No transaction name',Execute.TransactionName);
  4619. AssertEquals('Two arguments',2,Execute.Params.Count);
  4620. S:=TSQLSelectExpression(CheckClass(Execute.Params[0],TSQLSelectExpression));
  4621. AssertField(S.Select.Fields[0],'B','');
  4622. AssertTable(S.Select.Tables[0],'C','');
  4623. I:=TSQLIdentifierExpression(CheckClass(Execute.Params[1],TSQLIdentifierExpression));
  4624. AssertIdentifierName('Correct argument','D',I.Identifier);
  4625. AssertEquals('No return values',0,Execute.Returning.Count);
  4626. end;
  4627. procedure TTestExecuteProcedureParser.TestExecuteOneArgSelectErr;
  4628. begin
  4629. TestExecuteError('EXECUTE PROCEDURE A ((SELECT B FROM C), 2')
  4630. end;
  4631. procedure TTestExecuteProcedureParser.TestExecuteOneArgSelectErr2;
  4632. begin
  4633. TestExecuteError('EXECUTE PROCEDURE A (SELECT B FROM C), 2)')
  4634. end;
  4635. procedure TTestExecuteProcedureParser.TestExecuteOneArgSelectErr3;
  4636. begin
  4637. TestExecuteError('EXECUTE PROCEDURE A B)')
  4638. end;
  4639. procedure TTestExecuteProcedureParser.TestExecuteOneArgSelectErr4;
  4640. begin
  4641. TestExecuteError('EXECUTE PROCEDURE A B,C)')
  4642. end;
  4643. { EXECUTE PROCEDURE DELETE_EMPLOYEE2 1, 2;
  4644. EXECUTE PROCEDURE DELETE_EMPLOYEE2 (1, 2);
  4645. EXECUTE PROCEDURE DELETE_EMPLOYEE2 ((SELECT A FROM A), 2);
  4646. EXECUTE PROCEDURE DELETE_EMPLOYEE2 (SELECT A FROM A), 2;
  4647. }
  4648. { TTestConnectParser }
  4649. function TTestConnectParser.TestConnect(const ASource: String
  4650. ): TSQLConnectStatement;
  4651. begin
  4652. CreateParser(ASource);
  4653. FToFree:=Parser.Parse;
  4654. Result:=TSQLConnectStatement(CheckClass(FToFree,TSQLConnectStatement));
  4655. FConnect:=Result;
  4656. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  4657. end;
  4658. procedure TTestConnectParser.TestConnectError(const ASource: String);
  4659. begin
  4660. FErrSource:=ASource;
  4661. AssertException(ESQLParser,@TestParseError);
  4662. end;
  4663. procedure TTestConnectParser.TestConnectSimple;
  4664. begin
  4665. TestConnect('CONNECT ''/my/database/file''');
  4666. AssertEquals('Database name','/my/database/file',Connect.DatabaseName);
  4667. AssertEquals('User name','',Connect.UserName);
  4668. AssertEquals('Password','',Connect.Password);
  4669. AssertEquals('Role','',Connect.Role);
  4670. AssertEquals('Cache',0,Connect.Cache);
  4671. end;
  4672. procedure TTestConnectParser.TestConnectUser;
  4673. begin
  4674. TestConnect('CONNECT ''/my/database/file'' USER ''me''');
  4675. AssertEquals('Database name','/my/database/file',Connect.DatabaseName);
  4676. AssertEquals('User name','me',Connect.UserName);
  4677. AssertEquals('Password','',Connect.Password);
  4678. AssertEquals('Role','',Connect.Role);
  4679. AssertEquals('Cache',0,Connect.Cache);
  4680. end;
  4681. procedure TTestConnectParser.TestConnectPassword;
  4682. begin
  4683. TestConnect('CONNECT ''/my/database/file'' PASSWORD ''secret''');
  4684. AssertEquals('Database name','/my/database/file',Connect.DatabaseName);
  4685. AssertEquals('User name','',Connect.UserName);
  4686. AssertEquals('Password','secret',Connect.Password);
  4687. AssertEquals('Role','',Connect.Role);
  4688. AssertEquals('Cache',0,Connect.Cache);
  4689. end;
  4690. procedure TTestConnectParser.TestConnectUserPassword;
  4691. begin
  4692. TestConnect('CONNECT ''/my/database/file'' USER ''me'' PASSWORD ''secret''');
  4693. AssertEquals('Database name','/my/database/file',Connect.DatabaseName);
  4694. AssertEquals('User name','me',Connect.UserName);
  4695. AssertEquals('Password','secret',Connect.Password);
  4696. AssertEquals('Role','',Connect.Role);
  4697. AssertEquals('Cache',0,Connect.Cache);
  4698. end;
  4699. procedure TTestConnectParser.TestConnectUserPasswordRole;
  4700. begin
  4701. TestConnect('CONNECT ''/my/database/file'' USER ''me'' PASSWORD ''secret'' ROLE ''admin''');
  4702. AssertEquals('Database name','/my/database/file',Connect.DatabaseName);
  4703. AssertEquals('User name','me',Connect.UserName);
  4704. AssertEquals('Password','secret',Connect.Password);
  4705. AssertEquals('Role','admin',Connect.Role);
  4706. AssertEquals('Cache',0,Connect.Cache);
  4707. end;
  4708. procedure TTestConnectParser.TestConnectUserPasswordRoleCache;
  4709. begin
  4710. TestConnect('CONNECT ''/my/database/file'' USER ''me'' PASSWORD ''secret'' ROLE ''admin'' CACHE 2048');
  4711. AssertEquals('Database name','/my/database/file',Connect.DatabaseName);
  4712. AssertEquals('User name','me',Connect.UserName);
  4713. AssertEquals('Password','secret',Connect.Password);
  4714. AssertEquals('Role','admin',Connect.Role);
  4715. AssertEquals('Cache',2048,Connect.Cache);
  4716. end;
  4717. procedure TTestConnectParser.TestConnectSimpleCache;
  4718. begin
  4719. TestConnect('CONNECT ''/my/database/file'' CACHE 2048');
  4720. AssertEquals('Database name','/my/database/file',Connect.DatabaseName);
  4721. AssertEquals('User name','',Connect.UserName);
  4722. AssertEquals('Password','',Connect.Password);
  4723. AssertEquals('Role','',Connect.Role);
  4724. AssertEquals('Cache',2048,Connect.Cache);
  4725. end;
  4726. { TTestCreateDatabaseParser }
  4727. function TTestCreateDatabaseParser.TestCreate(const ASource: String
  4728. ): TSQLCreateDatabaseStatement;
  4729. begin
  4730. CreateParser(ASource);
  4731. FToFree:=Parser.Parse;
  4732. Result:=TSQLCreateDatabaseStatement(CheckClass(FToFree,TSQLCreateDatabaseStatement));
  4733. FCreateDB:=Result;
  4734. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  4735. end;
  4736. procedure TTestCreateDatabaseParser.TestCreateError(const ASource: String);
  4737. begin
  4738. FerrSource:=ASource;
  4739. AssertException(ESQLParser,@TestParseError);
  4740. end;
  4741. procedure TTestCreateDatabaseParser.TestSimple;
  4742. begin
  4743. TestCreate('CREATE DATABASE ''/my/database/file''');
  4744. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4745. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4746. AssertEquals('Username','',CreateDB.UserName);
  4747. AssertEquals('Password','',CreateDB.Password);
  4748. AssertNull('Character set',CreateDB.CharSet);
  4749. AssertEquals('Page size',0,CreateDB.PageSize);
  4750. AssertEquals('Length',0,CreateDB.Length);
  4751. AssertEquals('Secondary files',0,CreateDB.SecondaryFiles.Count);
  4752. end;
  4753. procedure TTestCreateDatabaseParser.TestSimpleSchema;
  4754. begin
  4755. TestCreate('CREATE SCHEMA ''/my/database/file''');
  4756. AssertEquals('schema',True,CreateDB.UseSchema);
  4757. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4758. AssertEquals('Username','',CreateDB.UserName);
  4759. AssertEquals('Password','',CreateDB.Password);
  4760. AssertNull('Character set',CreateDB.CharSet);
  4761. AssertEquals('Page size',0,CreateDB.PageSize);
  4762. AssertEquals('Length',0,CreateDB.Length);
  4763. AssertEquals('Secondary files',0,CreateDB.SecondaryFiles.Count);
  4764. end;
  4765. procedure TTestCreateDatabaseParser.TestSimpleUSer;
  4766. begin
  4767. TestCreate('CREATE DATABASE ''/my/database/file'' USER ''me''');
  4768. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4769. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4770. AssertEquals('Username','me',CreateDB.UserName);
  4771. AssertEquals('Password','',CreateDB.Password);
  4772. AssertNull('Character set',CreateDB.CharSet);
  4773. AssertEquals('Page size',0,CreateDB.PageSize);
  4774. AssertEquals('Length',0,CreateDB.Length);
  4775. AssertEquals('Secondary files',0,CreateDB.SecondaryFiles.Count);
  4776. end;
  4777. procedure TTestCreateDatabaseParser.TestSimpleUSerPassword;
  4778. begin
  4779. TestCreate('CREATE DATABASE ''/my/database/file'' USER ''me'' PASSWORD ''SECRET''');
  4780. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4781. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4782. AssertEquals('Username','me',CreateDB.UserName);
  4783. AssertEquals('Password','SECRET',CreateDB.Password);
  4784. AssertNull('Character set',CreateDB.CharSet);
  4785. AssertEquals('Page size',0,CreateDB.PageSize);
  4786. AssertEquals('Length',0,CreateDB.Length);
  4787. AssertEquals('Secondary files',0,CreateDB.SecondaryFiles.Count);
  4788. end;
  4789. procedure TTestCreateDatabaseParser.TestSimplePassword;
  4790. begin
  4791. TestCreate('CREATE DATABASE ''/my/database/file'' PASSWORD ''SECRET''');
  4792. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4793. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4794. AssertEquals('Username','',CreateDB.UserName);
  4795. AssertEquals('Password','SECRET',CreateDB.Password);
  4796. AssertNull('Character set',CreateDB.CharSet);
  4797. AssertEquals('Page size',0,CreateDB.PageSize);
  4798. AssertEquals('Length',0,CreateDB.Length);
  4799. AssertEquals('Secondary files',0,CreateDB.SecondaryFiles.Count);
  4800. end;
  4801. procedure TTestCreateDatabaseParser.TestPageSize;
  4802. begin
  4803. TestCreate('CREATE DATABASE ''/my/database/file'' PAGE_SIZE = 2048');
  4804. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4805. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4806. AssertEquals('Username','',CreateDB.UserName);
  4807. AssertEquals('Password','',CreateDB.Password);
  4808. AssertNull('Character set',CreateDB.CharSet);
  4809. AssertEquals('Page size',2048,CreateDB.PageSize);
  4810. AssertEquals('Length',0,CreateDB.Length);
  4811. AssertEquals('Secondary files',0,CreateDB.SecondaryFiles.Count);
  4812. end;
  4813. procedure TTestCreateDatabaseParser.TestPageSize2;
  4814. begin
  4815. TestCreate('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048');
  4816. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4817. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4818. AssertEquals('Username','',CreateDB.UserName);
  4819. AssertEquals('Password','',CreateDB.Password);
  4820. AssertNull('Character set',CreateDB.CharSet);
  4821. AssertEquals('Page size',2048,CreateDB.PageSize);
  4822. AssertEquals('Length',0,CreateDB.Length);
  4823. AssertEquals('Secondary files',0,CreateDB.SecondaryFiles.Count);
  4824. end;
  4825. procedure TTestCreateDatabaseParser.TestPageSizeLength;
  4826. begin
  4827. TestCreate('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048 LENGTH = 2000');
  4828. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4829. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4830. AssertEquals('Username','',CreateDB.UserName);
  4831. AssertEquals('Password','',CreateDB.Password);
  4832. AssertNull('Character set',CreateDB.CharSet);
  4833. AssertEquals('Page size',2048,CreateDB.PageSize);
  4834. AssertEquals('Length',2000,CreateDB.Length);
  4835. AssertEquals('Secondary files',0,CreateDB.SecondaryFiles.Count);
  4836. end;
  4837. procedure TTestCreateDatabaseParser.TestPageSizeLength2;
  4838. begin
  4839. TestCreate('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048 LENGTH 2000');
  4840. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4841. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4842. AssertEquals('Username','',CreateDB.UserName);
  4843. AssertEquals('Password','',CreateDB.Password);
  4844. AssertNull('Character set',CreateDB.CharSet);
  4845. AssertEquals('Page size',2048,CreateDB.PageSize);
  4846. AssertEquals('Length',2000,CreateDB.Length);
  4847. AssertEquals('Secondary files',0,CreateDB.SecondaryFiles.Count);
  4848. end;
  4849. procedure TTestCreateDatabaseParser.TestPageSizeLength3;
  4850. begin
  4851. TestCreate('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048 LENGTH 2000 PAGES');
  4852. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4853. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4854. AssertEquals('Username','',CreateDB.UserName);
  4855. AssertEquals('Password','',CreateDB.Password);
  4856. AssertNull('Character set',CreateDB.CharSet);
  4857. AssertEquals('Page size',2048,CreateDB.PageSize);
  4858. AssertEquals('Length',2000,CreateDB.Length);
  4859. AssertEquals('Secondary files',0,CreateDB.SecondaryFiles.Count);
  4860. end;
  4861. procedure TTestCreateDatabaseParser.TestPageSizeLength4;
  4862. begin
  4863. TestCreate('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048 LENGTH 2000 PAGE');
  4864. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4865. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4866. AssertEquals('Username','',CreateDB.UserName);
  4867. AssertEquals('Password','',CreateDB.Password);
  4868. AssertNull('Character set',CreateDB.CharSet);
  4869. AssertEquals('Page size',2048,CreateDB.PageSize);
  4870. AssertEquals('Length',2000,CreateDB.Length);
  4871. AssertEquals('Secondary files',0,CreateDB.SecondaryFiles.Count);
  4872. end;
  4873. procedure TTestCreateDatabaseParser.TestCharset;
  4874. begin
  4875. TestCreate('CREATE DATABASE ''/my/database/file'' DEFAULT CHARACTER SET UTF8');
  4876. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4877. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4878. AssertEquals('Username','',CreateDB.UserName);
  4879. AssertEquals('Password','',CreateDB.Password);
  4880. AssertIDentifierName('Character set','UTF8',CreateDB.CharSet);
  4881. AssertEquals('Page size',0,CreateDB.PageSize);
  4882. AssertEquals('Length',0,CreateDB.Length);
  4883. AssertEquals('Secondary files',0,CreateDB.SecondaryFiles.Count);
  4884. end;
  4885. procedure TTestCreateDatabaseParser.TestSecondaryFile1;
  4886. begin
  4887. TestCreate('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048 LENGTH 2000 FILE ''/my/database/file2''');
  4888. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4889. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4890. AssertEquals('Username','',CreateDB.UserName);
  4891. AssertEquals('Password','',CreateDB.Password);
  4892. AssertNull('Character set',CreateDB.CharSet);
  4893. AssertEquals('Page size',2048,CreateDB.PageSize);
  4894. AssertEquals('Length',2000,CreateDB.Length);
  4895. AssertEquals('Secondary files',1,CreateDB.SecondaryFiles.Count);
  4896. AssertSecondaryFile(CreateDB.SecondaryFiles[0],'/my/database/file2',0,0);
  4897. end;
  4898. procedure TTestCreateDatabaseParser.TestSecondaryFile2;
  4899. begin
  4900. TestCreate('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048 LENGTH 2000 FILE ''/my/database/file2'' LENGTH 1000');
  4901. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4902. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4903. AssertEquals('Username','',CreateDB.UserName);
  4904. AssertEquals('Password','',CreateDB.Password);
  4905. AssertNull('Character set',CreateDB.CharSet);
  4906. AssertEquals('Page size',2048,CreateDB.PageSize);
  4907. AssertEquals('Length',2000,CreateDB.Length);
  4908. AssertEquals('Secondary files',1,CreateDB.SecondaryFiles.Count);
  4909. AssertSecondaryFile(CreateDB.SecondaryFiles[0],'/my/database/file2',1000,0);
  4910. end;
  4911. procedure TTestCreateDatabaseParser.TestSecondaryFile3;
  4912. begin
  4913. TestCreate('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048 LENGTH 2000 FILE ''/my/database/file2'' LENGTH = 1000');
  4914. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4915. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4916. AssertEquals('Username','',CreateDB.UserName);
  4917. AssertEquals('Password','',CreateDB.Password);
  4918. AssertNull('Character set',CreateDB.CharSet);
  4919. AssertEquals('Page size',2048,CreateDB.PageSize);
  4920. AssertEquals('Length',2000,CreateDB.Length);
  4921. AssertEquals('Secondary files',1,CreateDB.SecondaryFiles.Count);
  4922. AssertSecondaryFile(CreateDB.SecondaryFiles[0],'/my/database/file2',1000,0);
  4923. end;
  4924. procedure TTestCreateDatabaseParser.TestSecondaryFile4;
  4925. begin
  4926. TestCreate('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048 LENGTH 2000 FILE ''/my/database/file2'' LENGTH = 1000 PAGE');
  4927. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4928. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4929. AssertEquals('Username','',CreateDB.UserName);
  4930. AssertEquals('Password','',CreateDB.Password);
  4931. AssertNull('Character set',CreateDB.CharSet);
  4932. AssertEquals('Page size',2048,CreateDB.PageSize);
  4933. AssertEquals('Length',2000,CreateDB.Length);
  4934. AssertEquals('Secondary files',1,CreateDB.SecondaryFiles.Count);
  4935. AssertSecondaryFile(CreateDB.SecondaryFiles[0],'/my/database/file2',1000,0);
  4936. end;
  4937. procedure TTestCreateDatabaseParser.TestSecondaryFile5;
  4938. begin
  4939. TestCreate('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048 LENGTH 2000 FILE ''/my/database/file2'' LENGTH = 1000 PAGES');
  4940. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4941. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4942. AssertEquals('Username','',CreateDB.UserName);
  4943. AssertEquals('Password','',CreateDB.Password);
  4944. AssertNull('Character set',CreateDB.CharSet);
  4945. AssertEquals('Page size',2048,CreateDB.PageSize);
  4946. AssertEquals('Length',2000,CreateDB.Length);
  4947. AssertEquals('Secondary files',1,CreateDB.SecondaryFiles.Count);
  4948. AssertSecondaryFile(CreateDB.SecondaryFiles[0],'/my/database/file2',1000,0);
  4949. end;
  4950. procedure TTestCreateDatabaseParser.TestSecondaryFile6;
  4951. begin
  4952. TestCreate('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048 LENGTH 2000 FILE ''/my/database/file2'' STARTING 3000 ');
  4953. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4954. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4955. AssertEquals('Username','',CreateDB.UserName);
  4956. AssertEquals('Password','',CreateDB.Password);
  4957. AssertNull('Character set',CreateDB.CharSet);
  4958. AssertEquals('Page size',2048,CreateDB.PageSize);
  4959. AssertEquals('Length',2000,CreateDB.Length);
  4960. AssertEquals('Secondary files',1,CreateDB.SecondaryFiles.Count);
  4961. AssertSecondaryFile(CreateDB.SecondaryFiles[0],'/my/database/file2',0,3000);
  4962. end;
  4963. procedure TTestCreateDatabaseParser.TestSecondaryFile7;
  4964. begin
  4965. TestCreate('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048 LENGTH 2000 FILE ''/my/database/file2'' STARTING AT 3000 ');
  4966. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4967. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4968. AssertEquals('Username','',CreateDB.UserName);
  4969. AssertEquals('Password','',CreateDB.Password);
  4970. AssertNull('Character set',CreateDB.CharSet);
  4971. AssertEquals('Page size',2048,CreateDB.PageSize);
  4972. AssertEquals('Length',2000,CreateDB.Length);
  4973. AssertEquals('Secondary files',1,CreateDB.SecondaryFiles.Count);
  4974. AssertSecondaryFile(CreateDB.SecondaryFiles[0],'/my/database/file2',0,3000);
  4975. end;
  4976. procedure TTestCreateDatabaseParser.TestSecondaryFile9;
  4977. begin
  4978. TestCreate('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048 LENGTH 2000 FILE ''/my/database/file2'' LENGTH 201 STARTING AT PAGE 3000 ');
  4979. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4980. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4981. AssertEquals('Username','',CreateDB.UserName);
  4982. AssertEquals('Password','',CreateDB.Password);
  4983. AssertNull('Character set',CreateDB.CharSet);
  4984. AssertEquals('Page size',2048,CreateDB.PageSize);
  4985. AssertEquals('Length',2000,CreateDB.Length);
  4986. AssertEquals('Secondary files',1,CreateDB.SecondaryFiles.Count);
  4987. AssertSecondaryFile(CreateDB.SecondaryFiles[0],'/my/database/file2',201,3000);
  4988. end;
  4989. procedure TTestCreateDatabaseParser.TestSecondaryFile10;
  4990. begin
  4991. TestCreate('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048 LENGTH 2000 FILE ''/my/database/file2'' STARTING AT PAGE 3000 LENGTH 201');
  4992. AssertEquals('Not schema',False,CreateDB.UseSchema);
  4993. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  4994. AssertEquals('Username','',CreateDB.UserName);
  4995. AssertEquals('Password','',CreateDB.Password);
  4996. AssertNull('Character set',CreateDB.CharSet);
  4997. AssertEquals('Page size',2048,CreateDB.PageSize);
  4998. AssertEquals('Length',2000,CreateDB.Length);
  4999. AssertEquals('Secondary files',1,CreateDB.SecondaryFiles.Count);
  5000. AssertSecondaryFile(CreateDB.SecondaryFiles[0],'/my/database/file2',201,3000);
  5001. end;
  5002. procedure TTestCreateDatabaseParser.TestSecondaryFile8;
  5003. begin
  5004. TestCreate('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048 LENGTH 2000 FILE ''/my/database/file2'' STARTING AT PAGE 3000 ');
  5005. AssertEquals('Not schema',False,CreateDB.UseSchema);
  5006. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  5007. AssertEquals('Username','',CreateDB.UserName);
  5008. AssertEquals('Password','',CreateDB.Password);
  5009. AssertNull('Character set',CreateDB.CharSet);
  5010. AssertEquals('Page size',2048,CreateDB.PageSize);
  5011. AssertEquals('Length',2000,CreateDB.Length);
  5012. AssertEquals('Secondary files',1,CreateDB.SecondaryFiles.Count);
  5013. AssertSecondaryFile(CreateDB.SecondaryFiles[0],'/my/database/file2',0,3000);
  5014. end;
  5015. procedure TTestCreateDatabaseParser.TestSecondaryFileS;
  5016. begin
  5017. TestCreate('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048 LENGTH 2000 FILE ''/my/database/file2'' FILE ''/my/database/file3'' ');
  5018. AssertEquals('Not schema',False,CreateDB.UseSchema);
  5019. AssertEquals('Database file','/my/database/file',CreateDB.FileName);
  5020. AssertEquals('Username','',CreateDB.UserName);
  5021. AssertEquals('Password','',CreateDB.Password);
  5022. AssertNull('Character set',CreateDB.CharSet);
  5023. AssertEquals('Page size',2048,CreateDB.PageSize);
  5024. AssertEquals('Length',2000,CreateDB.Length);
  5025. AssertEquals('Secondary files',2,CreateDB.SecondaryFiles.Count);
  5026. AssertSecondaryFile(CreateDB.SecondaryFiles[0],'/my/database/file2',0,0);
  5027. AssertSecondaryFile(CreateDB.SecondaryFiles[1],'/my/database/file3',0,0);
  5028. end;
  5029. procedure TTestCreateDatabaseParser.TestSecondaryFileError1;
  5030. begin
  5031. TestCreateError('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048 LENGTH 2000 FILE ''/my/database/file2'' LENGTH 3 LENGTH 2');
  5032. end;
  5033. procedure TTestCreateDatabaseParser.TestSecondaryFileError2;
  5034. begin
  5035. TestCreateError('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048 LENGTH 2000 FILE ''/my/database/file2'' STARTING 3 STARTING 2');
  5036. end;
  5037. procedure TTestCreateDatabaseParser.TestSecondaryFileError3;
  5038. begin
  5039. TestCreateError('CREATE DATABASE ''/my/database/file'' PAGE_SIZE 2048 LENGTH 2000 FILE ''/my/database/file2'' STARTING 3 LENGTH 2 STARTING 2');
  5040. end;
  5041. { TTestAlterDatabaseParser }
  5042. function TTestAlterDatabaseParser.TestAlter(const ASource: String
  5043. ): TSQLAlterDatabaseStatement;
  5044. begin
  5045. CreateParser(ASource);
  5046. FToFree:=Parser.Parse;
  5047. Result:=TSQLAlterDatabaseStatement(CheckClass(FToFree,TSQLAlterDatabaseStatement));
  5048. FAlterDB:=Result;
  5049. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  5050. end;
  5051. procedure TTestAlterDatabaseParser.TestAlterError(const ASource: String);
  5052. begin
  5053. FerrSource:=ASource;
  5054. AssertException(ESQLParser,@TestParseError);
  5055. end;
  5056. procedure TTestAlterDatabaseParser.TestSimple;
  5057. begin
  5058. TestAlter('ALTER DATABASE ADD FILE ''/my/file''');
  5059. AssertEquals('Operation count',1,AlterDB.Operations.Count);
  5060. AssertSecondaryFile(AlterDB.Operations[0],'/my/file',0,0);
  5061. end;
  5062. procedure TTestAlterDatabaseParser.TestStarting;
  5063. begin
  5064. TestAlter('ALTER DATABASE ADD FILE ''/my/file'' STARTING AT 100');
  5065. AssertEquals('Operation count',1,AlterDB.Operations.Count);
  5066. AssertSecondaryFile(AlterDB.Operations[0],'/my/file',0,100);
  5067. end;
  5068. procedure TTestAlterDatabaseParser.TestStartingLength;
  5069. begin
  5070. TestAlter('ALTER DATABASE ADD FILE ''/my/file'' STARTING AT 100 LENGTH 200');
  5071. AssertEquals('Operation count',1,AlterDB.Operations.Count);
  5072. AssertSecondaryFile(AlterDB.Operations[0],'/my/file',200,100);
  5073. end;
  5074. procedure TTestAlterDatabaseParser.TestFiles;
  5075. begin
  5076. TestAlter('ALTER DATABASE ADD FILE ''/my/file2'' ADD FILE ''/my/file3'' ');
  5077. AssertEquals('Operation count',2,AlterDB.Operations.Count);
  5078. AssertSecondaryFile(AlterDB.Operations[0],'/my/file2',0,0);
  5079. AssertSecondaryFile(AlterDB.Operations[1],'/my/file3',0,0);
  5080. end;
  5081. procedure TTestAlterDatabaseParser.TestFiles2;
  5082. begin
  5083. TestAlter('ALTER DATABASE ADD FILE ''/my/file2'' FILE ''/my/file3'' ');
  5084. AssertEquals('Operation count',2,AlterDB.Operations.Count);
  5085. AssertSecondaryFile(AlterDB.Operations[0],'/my/file2',0,0);
  5086. AssertSecondaryFile(AlterDB.Operations[1],'/my/file3',0,0);
  5087. end;
  5088. procedure TTestAlterDatabaseParser.TestFilesError;
  5089. begin
  5090. TestAlterError('ALTER DATABASE FILE ''/my/file2'' FILE ''/my/file3'' ');
  5091. end;
  5092. procedure TTestAlterDatabaseParser.TestError;
  5093. begin
  5094. TestAlterError('ALTER DATABASE ');
  5095. end;
  5096. procedure TTestAlterDatabaseParser.TestLength;
  5097. begin
  5098. TestAlter('ALTER DATABASE ADD FILE ''/my/file'' LENGTH 200');
  5099. AssertEquals('Operation count',1,AlterDB.Operations.Count);
  5100. AssertSecondaryFile(AlterDB.Operations[0],'/my/file',200,0);
  5101. end;
  5102. { TTestCreateViewParser }
  5103. function TTestCreateViewParser.TestCreate(const ASource: String
  5104. ): TSQLCreateViewStatement;
  5105. begin
  5106. CreateParser(ASource);
  5107. FToFree:=Parser.Parse;
  5108. Result:=TSQLCreateViewStatement(CheckClass(FToFree,TSQLCreateViewStatement));
  5109. FView:=Result;
  5110. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  5111. end;
  5112. procedure TTestCreateViewParser.TestCreateError(const ASource: String);
  5113. begin
  5114. FerrSource:=ASource;
  5115. AssertException(ESQLParser,@TestParseError);
  5116. end;
  5117. procedure TTestCreateViewParser.TestSimple;
  5118. Var
  5119. S : TSQLSelectStatement;
  5120. begin
  5121. TestCreate('CREATE VIEW A AS SELECT B FROM C');
  5122. AssertIdentifierName('View name','A',View.ObjectName);
  5123. AssertNotNull('field list created',View.Fields);
  5124. AssertEquals('No fields in list',0,View.Fields.Count);
  5125. S:=TSQLSelectStatement(CheckClass(View.select,TSQLSelectStatement));
  5126. AssertEquals('1 Field',1,S.Fields.Count);
  5127. AssertField(S.Fields[0],'B','');
  5128. AssertEquals('1 table',1,S.Tables.Count);
  5129. AssertTable(S.Tables[0],'C','');
  5130. AssertEquals('No with check option',False,View.WithCheckOption);
  5131. end;
  5132. procedure TTestCreateViewParser.TestFieldList;
  5133. Var
  5134. S : TSQLSelectStatement;
  5135. begin
  5136. TestCreate('CREATE VIEW A (D) AS SELECT B FROM C');
  5137. AssertIdentifierName('View name','A',View.ObjectName);
  5138. AssertNotNull('field list created',View.Fields);
  5139. AssertEquals('1 field in list',1,View.Fields.Count);
  5140. AssertIdentifierName('Field name','D',View.Fields[0]);
  5141. S:=TSQLSelectStatement(CheckClass(View.select,TSQLSelectStatement));
  5142. AssertEquals('1 Field',1,S.Fields.Count);
  5143. AssertField(S.Fields[0],'B','');
  5144. AssertEquals('1 table',1,S.Tables.Count);
  5145. AssertTable(S.Tables[0],'C','');
  5146. AssertEquals('No with check option',False,View.WithCheckOption);
  5147. end;
  5148. procedure TTestCreateViewParser.TestFieldList2;
  5149. Var
  5150. S : TSQLSelectStatement;
  5151. begin
  5152. TestCreate('CREATE VIEW A (B,C) AS SELECT D,E FROM F');
  5153. AssertIdentifierName('View name','A',View.ObjectName);
  5154. AssertNotNull('field list created',View.Fields);
  5155. AssertEquals('2 fields in list',2,View.Fields.Count);
  5156. AssertIdentifierName('Field name','B',View.Fields[0]);
  5157. AssertIdentifierName('Field name','C',View.Fields[1]);
  5158. S:=TSQLSelectStatement(CheckClass(View.select,TSQLSelectStatement));
  5159. AssertEquals('2 Fields in select',2,S.Fields.Count);
  5160. AssertField(S.Fields[0],'D','');
  5161. AssertField(S.Fields[1],'E','');
  5162. AssertEquals('1 table',1,S.Tables.Count);
  5163. AssertTable(S.Tables[0],'F','');
  5164. AssertEquals('No with check option',False,View.WithCheckOption);
  5165. end;
  5166. procedure TTestCreateViewParser.TestSimpleWithCheckoption;
  5167. Var
  5168. S : TSQLSelectStatement;
  5169. begin
  5170. TestCreate('CREATE VIEW A AS SELECT B FROM C WITH CHECK OPTION');
  5171. AssertIdentifierName('View name','A',View.ObjectName);
  5172. AssertNotNull('field list created',View.Fields);
  5173. AssertEquals('No fields in list',0,View.Fields.Count);
  5174. S:=TSQLSelectStatement(CheckClass(View.select,TSQLSelectStatement));
  5175. AssertEquals('1 Field',1,S.Fields.Count);
  5176. AssertField(S.Fields[0],'B','');
  5177. AssertEquals('1 table',1,S.Tables.Count);
  5178. AssertTable(S.Tables[0],'C','');
  5179. AssertEquals('With check option',True,View.WithCheckOption);
  5180. end;
  5181. { TTestCreateShadowParser }
  5182. function TTestCreateShadowParser.TestCreate(const ASource: String
  5183. ): TSQLCreateShadowStatement;
  5184. begin
  5185. CreateParser(ASource);
  5186. FToFree:=Parser.Parse;
  5187. Result:=TSQLCreateShadowStatement(CheckClass(FToFree,TSQLCreateShadowStatement));
  5188. FShadow:=Result;
  5189. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  5190. end;
  5191. procedure TTestCreateShadowParser.TestCreateError(const ASource: String);
  5192. begin
  5193. FerrSource:=ASource;
  5194. AssertException(ESQLParser,@TestParseError);
  5195. end;
  5196. procedure TTestCreateShadowParser.TestSimple;
  5197. begin
  5198. TestCreate('CREATE SHADOW 1 ''/my/file''');
  5199. AssertEquals('Not manual',False,Shadow.Manual);
  5200. AssertEquals('Not conditional',False,Shadow.COnditional);
  5201. AssertEquals('Filename','/my/file',Shadow.FileName);
  5202. AssertEquals('No length',0,Shadow.Length);
  5203. AssertEquals('No secondary files',0,Shadow.SecondaryFiles.Count);
  5204. end;
  5205. procedure TTestCreateShadowParser.TestLength;
  5206. begin
  5207. TestCreate('CREATE SHADOW 1 ''/my/file'' LENGTH 2');
  5208. AssertEquals('Not manual',False,Shadow.Manual);
  5209. AssertEquals('Not conditional',False,Shadow.COnditional);
  5210. AssertEquals('Filename','/my/file',Shadow.FileName);
  5211. AssertEquals('No length',2,Shadow.Length);
  5212. AssertEquals('No secondary files',0,Shadow.SecondaryFiles.Count);
  5213. end;
  5214. procedure TTestCreateShadowParser.TestLength2;
  5215. begin
  5216. TestCreate('CREATE SHADOW 1 ''/my/file'' LENGTH = 2');
  5217. AssertEquals('Not manual',False,Shadow.Manual);
  5218. AssertEquals('Not conditional',False,Shadow.COnditional);
  5219. AssertEquals('Filename','/my/file',Shadow.FileName);
  5220. AssertEquals('No length',2,Shadow.Length);
  5221. AssertEquals('No secondary files',0,Shadow.SecondaryFiles.Count);
  5222. end;
  5223. procedure TTestCreateShadowParser.TestLength3;
  5224. begin
  5225. TestCreate('CREATE SHADOW 1 ''/my/file'' LENGTH = 2 PAGE');
  5226. AssertEquals('Not manual',False,Shadow.Manual);
  5227. AssertEquals('Not conditional',False,Shadow.COnditional);
  5228. AssertEquals('Filename','/my/file',Shadow.FileName);
  5229. AssertEquals('No length',2,Shadow.Length);
  5230. AssertEquals('No secondary files',0,Shadow.SecondaryFiles.Count);
  5231. end;
  5232. procedure TTestCreateShadowParser.TestLength4;
  5233. begin
  5234. TestCreate('CREATE SHADOW 1 ''/my/file'' LENGTH = 2 PAGES');
  5235. AssertEquals('Not manual',False,Shadow.Manual);
  5236. AssertEquals('Not conditional',False,Shadow.COnditional);
  5237. AssertEquals('Filename','/my/file',Shadow.FileName);
  5238. AssertEquals('No length',2,Shadow.Length);
  5239. AssertEquals('No secondary files',0,Shadow.SecondaryFiles.Count);
  5240. end;
  5241. procedure TTestCreateShadowParser.TestSecondaryFile1;
  5242. begin
  5243. TestCreate('CREATE SHADOW 1 ''/my/file'' LENGTH 2 FILE ''/my/file2''');
  5244. AssertEquals('Not manual',False,Shadow.Manual);
  5245. AssertEquals('Not conditional',False,Shadow.COnditional);
  5246. AssertEquals('Filename','/my/file',Shadow.FileName);
  5247. AssertEquals('No length',2,Shadow.Length);
  5248. AssertEquals('1 secondary file',1,Shadow.SecondaryFiles.Count);
  5249. AssertSecondaryFile(Shadow.SecondaryFiles[0],'/my/file2',0,0);
  5250. end;
  5251. procedure TTestCreateShadowParser.TestSecondaryFile2;
  5252. begin
  5253. TestCreate('CREATE SHADOW 1 ''/my/file'' LENGTH 2 FILE ''/my/file2'' LENGTH 1000');
  5254. AssertEquals('Not manual',False,Shadow.Manual);
  5255. AssertEquals('Not conditional',False,Shadow.COnditional);
  5256. AssertEquals('Filename','/my/file',Shadow.FileName);
  5257. AssertEquals('No length',2,Shadow.Length);
  5258. AssertEquals('1 secondary file',1,Shadow.SecondaryFiles.Count);
  5259. AssertSecondaryFile(Shadow.SecondaryFiles[0],'/my/file2',1000,0);
  5260. end;
  5261. procedure TTestCreateShadowParser.TestSecondaryFile3;
  5262. begin
  5263. TestCreate('CREATE SHADOW 1 ''/my/file'' LENGTH 2 FILE ''/my/file2'' LENGTH = 1000');
  5264. AssertEquals('Not manual',False,Shadow.Manual);
  5265. AssertEquals('Not conditional',False,Shadow.COnditional);
  5266. AssertEquals('Filename','/my/file',Shadow.FileName);
  5267. AssertEquals('No length',2,Shadow.Length);
  5268. AssertEquals('1 secondary file',1,Shadow.SecondaryFiles.Count);
  5269. AssertSecondaryFile(Shadow.SecondaryFiles[0],'/my/file2',1000,0);
  5270. end;
  5271. procedure TTestCreateShadowParser.TestSecondaryFile4;
  5272. begin
  5273. TestCreate('CREATE SHADOW 1 ''/my/file'' LENGTH 2 FILE ''/my/file2'' LENGTH = 1000 PAGE');
  5274. AssertEquals('Not manual',False,Shadow.Manual);
  5275. AssertEquals('Not conditional',False,Shadow.COnditional);
  5276. AssertEquals('Filename','/my/file',Shadow.FileName);
  5277. AssertEquals('No length',2,Shadow.Length);
  5278. AssertEquals('1 secondary file',1,Shadow.SecondaryFiles.Count);
  5279. AssertSecondaryFile(Shadow.SecondaryFiles[0],'/my/file2',1000,0);
  5280. end;
  5281. procedure TTestCreateShadowParser.TestSecondaryFile5;
  5282. begin
  5283. TestCreate('CREATE SHADOW 1 ''/my/file'' LENGTH 2 FILE ''/my/file2'' LENGTH = 1000 PAGES');
  5284. AssertEquals('Not manual',False,Shadow.Manual);
  5285. AssertEquals('Not conditional',False,Shadow.COnditional);
  5286. AssertEquals('Filename','/my/file',Shadow.FileName);
  5287. AssertEquals('No length',2,Shadow.Length);
  5288. AssertEquals('1 secondary file',1,Shadow.SecondaryFiles.Count);
  5289. AssertSecondaryFile(Shadow.SecondaryFiles[0],'/my/file2',1000,0);
  5290. end;
  5291. procedure TTestCreateShadowParser.TestSecondaryFile6;
  5292. begin
  5293. TestCreate('CREATE SHADOW 1 ''/my/file'' LENGTH 2 FILE ''/my/file2'' STARTING 3000');
  5294. AssertEquals('Not manual',False,Shadow.Manual);
  5295. AssertEquals('Not conditional',False,Shadow.COnditional);
  5296. AssertEquals('Filename','/my/file',Shadow.FileName);
  5297. AssertEquals('No length',2,Shadow.Length);
  5298. AssertEquals('1 secondary file',1,Shadow.SecondaryFiles.Count);
  5299. AssertSecondaryFile(Shadow.SecondaryFiles[0],'/my/file2',0,3000);
  5300. end;
  5301. procedure TTestCreateShadowParser.TestSecondaryFile7;
  5302. begin
  5303. TestCreate('CREATE SHADOW 1 ''/my/file'' LENGTH 2 FILE ''/my/file2'' STARTING AT 3000');
  5304. AssertEquals('Not manual',False,Shadow.Manual);
  5305. AssertEquals('Not conditional',False,Shadow.COnditional);
  5306. AssertEquals('Filename','/my/file',Shadow.FileName);
  5307. AssertEquals('No length',2,Shadow.Length);
  5308. AssertEquals('1 secondary file',1,Shadow.SecondaryFiles.Count);
  5309. AssertSecondaryFile(Shadow.SecondaryFiles[0],'/my/file2',0,3000);
  5310. end;
  5311. procedure TTestCreateShadowParser.TestSecondaryFile8;
  5312. begin
  5313. TestCreate('CREATE SHADOW 1 ''/my/file'' LENGTH 2 FILE ''/my/file2'' STARTING AT PAGE 3000');
  5314. AssertEquals('Not manual',False,Shadow.Manual);
  5315. AssertEquals('Not conditional',False,Shadow.COnditional);
  5316. AssertEquals('Filename','/my/file',Shadow.FileName);
  5317. AssertEquals('No length',2,Shadow.Length);
  5318. AssertEquals('1 secondary file',1,Shadow.SecondaryFiles.Count);
  5319. AssertSecondaryFile(Shadow.SecondaryFiles[0],'/my/file2',0,3000);
  5320. end;
  5321. procedure TTestCreateShadowParser.TestSecondaryFileS;
  5322. begin
  5323. TestCreate('CREATE SHADOW 1 ''/my/file'' LENGTH 2 FILE ''/my/file2'' FILE ''/my/file3''');
  5324. AssertEquals('Not manual',False,Shadow.Manual);
  5325. AssertEquals('Not conditional',False,Shadow.COnditional);
  5326. AssertEquals('Filename','/my/file',Shadow.FileName);
  5327. AssertEquals('No length',2,Shadow.Length);
  5328. AssertEquals('2 secondary file',2,Shadow.SecondaryFiles.Count);
  5329. AssertSecondaryFile(Shadow.SecondaryFiles[0],'/my/file2',0,0);
  5330. AssertSecondaryFile(Shadow.SecondaryFiles[1],'/my/file3',0,0);
  5331. end;
  5332. { TTestProcedureStatement }
  5333. function TTestProcedureStatement.TestStatement(const ASource: String
  5334. ): TSQLStatement;
  5335. begin
  5336. CreateParser(ASource);
  5337. Parser.GetNextToken;
  5338. FToFree:=Parser.ParseProcedureStatements;
  5339. If not (FToFree is TSQLStatement) then
  5340. Fail('Not a TSQLStatement');
  5341. Result:=TSQLStatement(FToFree);
  5342. FSTatement:=Result;
  5343. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  5344. end;
  5345. procedure TTestProcedureStatement.TestParseStatementError;
  5346. begin
  5347. CreateParser(FErrSource);
  5348. FToFree:=Parser.ParseProcedureStatements;
  5349. end;
  5350. procedure TTestProcedureStatement.TestStatementError(const ASource: String);
  5351. begin
  5352. FerrSource:=ASource;
  5353. AssertException(ESQLParser,@TestParseStatementError);
  5354. end;
  5355. procedure TTestProcedureStatement.TestException;
  5356. Var
  5357. E : TSQLExceptionStatement;
  5358. begin
  5359. E:=TSQLExceptionStatement(CheckClass(TestStatement('EXCEPTION MYE'),TSQLExceptionStatement));
  5360. AssertIdentifierName('Exception name','MYE',E.ExceptionName);
  5361. end;
  5362. procedure TTestProcedureStatement.TestExceptionError;
  5363. begin
  5364. TestStatementError('EXCEPTION ''MYE''');
  5365. end;
  5366. procedure TTestProcedureStatement.TestExit;
  5367. Var
  5368. E : TSQLExitStatement;
  5369. begin
  5370. E:=TSQLExitStatement(CheckClass(TestStatement('EXIT'),TSQLExitStatement));
  5371. end;
  5372. procedure TTestProcedureStatement.TestSuspend;
  5373. Var
  5374. E : TSQLSuspendStatement;
  5375. begin
  5376. E:=TSQLSuspendStatement(CheckClass(TestStatement('Suspend'),TSQLSuspendStatement));
  5377. end;
  5378. procedure TTestProcedureStatement.TestEmptyBlock;
  5379. Var
  5380. B : TSQLStatementBlock;
  5381. begin
  5382. B:=TSQLStatementBlock(CheckClass(TestStatement('BEGIN END'),TSQLStatementBlock));
  5383. AssertEquals('No statements',0,B.Statements.Count)
  5384. end;
  5385. procedure TTestProcedureStatement.TestExitBlock;
  5386. Var
  5387. B : TSQLStatementBlock;
  5388. begin
  5389. B:=TSQLStatementBlock(CheckClass(TestStatement('BEGIN EXIT; END'),TSQLStatementBlock));
  5390. AssertEquals('1 statement',1,B.Statements.Count);
  5391. CheckClass(B.Statements[0],TSQLExitStatement);
  5392. end;
  5393. procedure TTestProcedureStatement.TestExitBlockError;
  5394. begin
  5395. TestStatementError('BEGIN EXIT END')
  5396. end;
  5397. procedure TTestProcedureStatement.TestPostEvent;
  5398. Var
  5399. P : TSQLPostEventStatement;
  5400. begin
  5401. P:=TSQLPostEventStatement(CheckClass(TestStatement('POST_EVENT ''MYEVENT'''),TSQLPostEventStatement));
  5402. AssertEquals('Correct event name','MYEVENT' , P.EventName);
  5403. AssertNull('No event column',P.ColName);
  5404. end;
  5405. procedure TTestProcedureStatement.TestPostEventColName;
  5406. Var
  5407. P : TSQLPostEventStatement;
  5408. begin
  5409. P:=TSQLPostEventStatement(CheckClass(TestStatement('POST_EVENT MyColName'),TSQLPostEventStatement));
  5410. AssertEquals('Correct event name','' , P.EventName);
  5411. AssertIdentifierName('event column','MyColName',P.ColName);
  5412. end;
  5413. procedure TTestProcedureStatement.TestPostError;
  5414. begin
  5415. TestStatementError('POST_EVENT 1');
  5416. end;
  5417. procedure TTestProcedureStatement.TestAssignSimple;
  5418. Var
  5419. A : TSQLAssignStatement;
  5420. E : TSQLLiteralExpression;
  5421. I : TSQLIntegerLiteral;
  5422. begin
  5423. A:=TSQLAssignStatement(CheckClass(TestStatement('A=1'),TSQLAssignStatement));
  5424. AssertIdentifierName('Variable name','A',A.Variable);
  5425. E:=TSQLLiteralExpression(CheckClass(A.Expression,TSQLLiteralExpression));
  5426. I:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  5427. AssertEquals('Correct value',1,I.Value);
  5428. end;
  5429. procedure TTestProcedureStatement.TestAssignSimpleNew;
  5430. Var
  5431. A : TSQLAssignStatement;
  5432. E : TSQLLiteralExpression;
  5433. I : TSQLIntegerLiteral;
  5434. begin
  5435. A:=TSQLAssignStatement(CheckClass(TestStatement('NEW.A=1'),TSQLAssignStatement));
  5436. AssertIdentifierName('Variable name','NEW.A',A.Variable);
  5437. E:=TSQLLiteralExpression(CheckClass(A.Expression,TSQLLiteralExpression));
  5438. I:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  5439. AssertEquals('Correct value',1,I.Value);
  5440. end;
  5441. procedure TTestProcedureStatement.TestAssignSelect;
  5442. Var
  5443. A : TSQLAssignStatement;
  5444. S : TSQLSelectExpression;
  5445. begin
  5446. A:=TSQLAssignStatement(CheckClass(TestStatement('A=(SELECT B FROM C)'),TSQLAssignStatement));
  5447. AssertIdentifierName('Variable name','A',A.Variable);
  5448. S:=TSQLSelectExpression(CheckClass(A.Expression,TSQLSelectExpression));
  5449. AssertEquals('Field count',1,S.Select.Fields.Count);
  5450. AssertEquals('Table count',1,S.Select.Tables.Count);
  5451. AssertField(S.Select.Fields[0],'B','');
  5452. AssertTable(S.Select.Tables[0],'C','');
  5453. end;
  5454. procedure TTestProcedureStatement.TestBlockAssignSimple;
  5455. Var
  5456. A : TSQLAssignStatement;
  5457. E : TSQLLiteralExpression;
  5458. I : TSQLIntegerLiteral;
  5459. B : TSQLStatementBlock;
  5460. begin
  5461. B:=TSQLStatementBlock(CheckClass(TestStatement('BEGIN A=1; EXIT; END'),TSQLStatementBlock));
  5462. AssertEquals('2 statements',2,B.Statements.Count);
  5463. CheckClass(B.Statements[1],TSQLExitStatement);
  5464. A:=TSQLAssignStatement(CheckClass(B.Statements[0],TSQLAssignStatement));
  5465. AssertIdentifierName('Variable name','A',A.Variable);
  5466. E:=TSQLLiteralExpression(CheckClass(A.Expression,TSQLLiteralExpression));
  5467. I:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  5468. AssertEquals('Correct value',1,I.Value);
  5469. end;
  5470. procedure TTestProcedureStatement.TestIf;
  5471. Var
  5472. I : TSQLIfStatement;
  5473. C : TSQLBinaryExpression;
  5474. E : TSQLLiteralExpression;
  5475. A : TSQLIdentifierExpression;
  5476. LI : TSQLIntegerLiteral;
  5477. begin
  5478. I:=TSQLIfStatement(CheckClass(TestStatement('IF (A=1) THEN EXIT'),TSQLIfStatement));
  5479. C:=TSQLBinaryExpression(CheckClass(I.Condition,TSQLBinaryExpression));
  5480. AssertEquals('Equals',boEq,C.Operation);
  5481. E:=TSQLLiteralExpression(CheckClass(C.Right,TSQLLiteralExpression));
  5482. LI:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  5483. AssertEquals('Correct value',1,LI.Value);
  5484. A:=TSQLIdentifierExpression(CheckClass(C.Left,TSQLIdentifierExpression));
  5485. AssertIdentifierName('Variable name','A',A.Identifier);
  5486. CheckClass(I.TrueBranch,TSQLExitStatement);
  5487. end;
  5488. procedure TTestProcedureStatement.TestIfBlock;
  5489. Var
  5490. I : TSQLIfStatement;
  5491. C : TSQLBinaryExpression;
  5492. E : TSQLLiteralExpression;
  5493. A : TSQLIdentifierExpression;
  5494. LI : TSQLIntegerLiteral;
  5495. B : TSQLStatementBlock;
  5496. begin
  5497. I:=TSQLIfStatement(CheckClass(TestStatement('IF (A=1) THEN BEGIN EXIT; END'),TSQLIfStatement));
  5498. C:=TSQLBinaryExpression(CheckClass(I.Condition,TSQLBinaryExpression));
  5499. AssertEquals('Equals',boEq,C.Operation);
  5500. E:=TSQLLiteralExpression(CheckClass(C.Right,TSQLLiteralExpression));
  5501. LI:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  5502. AssertEquals('Correct value',1,LI.Value);
  5503. A:=TSQLIdentifierExpression(CheckClass(C.Left,TSQLIdentifierExpression));
  5504. AssertIdentifierName('Variable name','A',A.Identifier);
  5505. B:=TSQLStatementBlock(CheckClass(I.TrueBranch,TSQLStatementBlock));
  5506. AssertEquals('1 statement',1,B.Statements.Count);
  5507. CheckClass(B.Statements[0],TSQLExitStatement);
  5508. end;
  5509. procedure TTestProcedureStatement.TestIfElse;
  5510. Var
  5511. I : TSQLIfStatement;
  5512. C : TSQLBinaryExpression;
  5513. E : TSQLLiteralExpression;
  5514. A : TSQLIdentifierExpression;
  5515. LI : TSQLIntegerLiteral;
  5516. begin
  5517. I:=TSQLIfStatement(CheckClass(TestStatement('IF (A=1) THEN EXIT; ELSE SUSPEND'),TSQLIfStatement));
  5518. C:=TSQLBinaryExpression(CheckClass(I.Condition,TSQLBinaryExpression));
  5519. AssertEquals('Equals',boEq,C.Operation);
  5520. E:=TSQLLiteralExpression(CheckClass(C.Right,TSQLLiteralExpression));
  5521. LI:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  5522. AssertEquals('Correct value',1,LI.Value);
  5523. A:=TSQLIdentifierExpression(CheckClass(C.Left,TSQLIdentifierExpression));
  5524. AssertIdentifierName('Variable name','A',A.Identifier);
  5525. CheckClass(I.TrueBranch,TSQLExitStatement);
  5526. CheckClass(I.FalseBranch,TSQLSuspendStatement);
  5527. end;
  5528. procedure TTestProcedureStatement.TestIfBlockElse;
  5529. Var
  5530. I : TSQLIfStatement;
  5531. C : TSQLBinaryExpression;
  5532. E : TSQLLiteralExpression;
  5533. A : TSQLIdentifierExpression;
  5534. LI : TSQLIntegerLiteral;
  5535. B : TSQLStatementBlock;
  5536. begin
  5537. I:=TSQLIfStatement(CheckClass(TestStatement('IF (A=1) THEN BEGIN EXIT; END ELSE SUSPEND'),TSQLIfStatement));
  5538. C:=TSQLBinaryExpression(CheckClass(I.Condition,TSQLBinaryExpression));
  5539. AssertEquals('Equals',boEq,C.Operation);
  5540. E:=TSQLLiteralExpression(CheckClass(C.Right,TSQLLiteralExpression));
  5541. LI:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  5542. AssertEquals('Correct value',1,LI.Value);
  5543. A:=TSQLIdentifierExpression(CheckClass(C.Left,TSQLIdentifierExpression));
  5544. AssertIdentifierName('Variable name','A',A.Identifier);
  5545. B:=TSQLStatementBlock(CheckClass(I.TrueBranch,TSQLStatementBlock));
  5546. AssertEquals('1 statement',1,B.Statements.Count);
  5547. CheckClass(B.Statements[0],TSQLExitStatement);
  5548. CheckClass(I.FalseBranch,TSQLSuspendStatement);
  5549. end;
  5550. procedure TTestProcedureStatement.TestIfElseError;
  5551. begin
  5552. TestStatementError('IF (A=B) THEN EXIT ELSE SUSPEND');
  5553. TestStatementError('IF (A=B) THEN BEGIN EXIT; END; ELSE SUSPEND');
  5554. end;
  5555. procedure TTestProcedureStatement.TestIfBlockElseBlock;
  5556. Var
  5557. I : TSQLIfStatement;
  5558. C : TSQLBinaryExpression;
  5559. E : TSQLLiteralExpression;
  5560. A : TSQLIdentifierExpression;
  5561. LI : TSQLIntegerLiteral;
  5562. B : TSQLStatementBlock;
  5563. begin
  5564. I:=TSQLIfStatement(CheckClass(TestStatement('IF (A=1) THEN BEGIN EXIT; END ELSE BEGIN SUSPEND; END'),TSQLIfStatement));
  5565. C:=TSQLBinaryExpression(CheckClass(I.Condition,TSQLBinaryExpression));
  5566. AssertEquals('Equals',boEq,C.Operation);
  5567. E:=TSQLLiteralExpression(CheckClass(C.Right,TSQLLiteralExpression));
  5568. LI:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  5569. AssertEquals('Correct value',1,LI.Value);
  5570. A:=TSQLIdentifierExpression(CheckClass(C.Left,TSQLIdentifierExpression));
  5571. AssertIdentifierName('Variable name','A',A.Identifier);
  5572. B:=TSQLStatementBlock(CheckClass(I.TrueBranch,TSQLStatementBlock));
  5573. AssertEquals('1 statement',1,B.Statements.Count);
  5574. CheckClass(B.Statements[0],TSQLExitStatement);
  5575. B:=TSQLStatementBlock(CheckClass(I.FalseBranch,TSQLStatementBlock));
  5576. AssertEquals('1 statement',1,B.Statements.Count);
  5577. CheckClass(B.Statements[0],TSQLSuspendStatement);
  5578. end;
  5579. procedure TTestProcedureStatement.TestIfErrorBracketLeft;
  5580. begin
  5581. TestStatementError('IF A=1) THEN EXIT');
  5582. end;
  5583. procedure TTestProcedureStatement.TestIfErrorBracketRight;
  5584. begin
  5585. TestStatementError('IF (A=1 THEN EXIT');
  5586. end;
  5587. procedure TTestProcedureStatement.TestIfErrorNoThen;
  5588. begin
  5589. TestStatementError('IF (A=1) EXIT');
  5590. end;
  5591. procedure TTestProcedureStatement.TestIfErrorSemicolonElse;
  5592. begin
  5593. TestStatementError('IF (A=1) THEN EXIT; ELSE SUSPEND');
  5594. end;
  5595. procedure TTestProcedureStatement.TestWhile;
  5596. Var
  5597. W : TSQLWhileStatement;
  5598. C : TSQLBinaryExpression;
  5599. E : TSQLLiteralExpression;
  5600. A : TSQLIdentifierExpression;
  5601. LI : TSQLIntegerLiteral;
  5602. SA : TSQLAssignStatement;
  5603. begin
  5604. W:=TSQLWhileStatement(CheckClass(TestStatement('WHILE (A>1) DO A=A-1'),TSQLWhileStatement));
  5605. C:=TSQLBinaryExpression(CheckClass(W.Condition,TSQLBinaryExpression));
  5606. AssertEquals('Equals',boGT,C.Operation);
  5607. E:=TSQLLiteralExpression(CheckClass(C.Right,TSQLLiteralExpression));
  5608. LI:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  5609. AssertEquals('Correct value',1,LI.Value);
  5610. A:=TSQLIdentifierExpression(CheckClass(C.Left,TSQLIdentifierExpression));
  5611. AssertIdentifierName('Variable name','A',A.Identifier);
  5612. SA:=TSQLAssignStatement(CheckClass(W.Statement,TSQLAssignStatement));
  5613. AssertIdentifierName('Variable name','A',SA.Variable);
  5614. // Check assignment expression
  5615. C:=TSQLBinaryExpression(CheckClass(SA.Expression,TSQLBinaryExpression));
  5616. AssertEquals('Equals',boAdd,C.Operation);
  5617. // Left operand
  5618. A:=TSQLIdentifierExpression(CheckClass(C.Left,TSQLIdentifierExpression));
  5619. AssertIdentifierName('Variable name','A',A.Identifier);
  5620. // Right operand
  5621. E:=TSQLLiteralExpression(CheckClass(C.Right,TSQLLiteralExpression));
  5622. LI:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  5623. AssertEquals('Correct value',-1,LI.Value);
  5624. end;
  5625. procedure TTestProcedureStatement.TestWhileBlock;
  5626. Var
  5627. W : TSQLWhileStatement;
  5628. C : TSQLBinaryExpression;
  5629. E : TSQLLiteralExpression;
  5630. A : TSQLIdentifierExpression;
  5631. LI : TSQLIntegerLiteral;
  5632. SA : TSQLAssignStatement;
  5633. B : TSQLStatementBlock;
  5634. begin
  5635. W:=TSQLWhileStatement(CheckClass(TestStatement('WHILE (A>1) DO BEGIN A=A-1; END'),TSQLWhileStatement));
  5636. C:=TSQLBinaryExpression(CheckClass(W.Condition,TSQLBinaryExpression));
  5637. AssertEquals('Equals',boGT,C.Operation);
  5638. E:=TSQLLiteralExpression(CheckClass(C.Right,TSQLLiteralExpression));
  5639. LI:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  5640. AssertEquals('Correct value',1,LI.Value);
  5641. A:=TSQLIdentifierExpression(CheckClass(C.Left,TSQLIdentifierExpression));
  5642. AssertIdentifierName('Variable name','A',A.Identifier);
  5643. B:=TSQLStatementBlock(CheckClass(W.Statement,TSQLStatementBlock));
  5644. AssertEquals('One statement',1,B.Statements.Count);
  5645. SA:=TSQLAssignStatement(CheckClass(B.Statements[0],TSQLAssignStatement));
  5646. AssertIdentifierName('Variable name','A',SA.Variable);
  5647. // Check assignment expression
  5648. C:=TSQLBinaryExpression(CheckClass(SA.Expression,TSQLBinaryExpression));
  5649. AssertEquals('Equals',boAdd,C.Operation);
  5650. // Left operand
  5651. A:=TSQLIdentifierExpression(CheckClass(C.Left,TSQLIdentifierExpression));
  5652. AssertIdentifierName('Variable name','A',A.Identifier);
  5653. // Right operand
  5654. E:=TSQLLiteralExpression(CheckClass(C.Right,TSQLLiteralExpression));
  5655. LI:=TSQLIntegerLiteral(CheckClass(E.Literal,TSQLIntegerLiteral));
  5656. AssertEquals('Correct value',-1,LI.Value);
  5657. end;
  5658. procedure TTestProcedureStatement.TestWhileErrorBracketLeft;
  5659. begin
  5660. TestStatementError('WHILE A>1) DO A=A-1');
  5661. end;
  5662. procedure TTestProcedureStatement.TestWhileErrorBracketRight;
  5663. begin
  5664. TestStatementError('WHILE (A>1 DO A=A-1');
  5665. end;
  5666. procedure TTestProcedureStatement.TestWhileErrorNoDo;
  5667. begin
  5668. TestStatementError('WHILE (A>1) A=A-1');
  5669. end;
  5670. procedure TTestProcedureStatement.TestWhenAny;
  5671. Var
  5672. W : TSQLWhenStatement;
  5673. begin
  5674. W:=TSQLWhenStatement(CheckClass(TestStatement('WHEN ANY DO EXIT'),TSQLWhenStatement));
  5675. AssertEquals('No error codes',0,W.Errors.Count);
  5676. AssertEquals('Any error',True,W.AnyError);
  5677. CheckClass(W.Statement,TSQLExitStatement);
  5678. end;
  5679. procedure TTestProcedureStatement.TestWhenSQLCode;
  5680. Var
  5681. W : TSQLWhenStatement;
  5682. E : TSQLWhenSQLError;
  5683. begin
  5684. W:=TSQLWhenStatement(CheckClass(TestStatement('WHEN SQLCODE 1 DO EXIT'),TSQLWhenStatement));
  5685. AssertEquals('Not Any error',False,W.AnyError);
  5686. AssertEquals('1 error code',1,W.Errors.Count);
  5687. CheckClass(W.Statement,TSQLExitStatement);
  5688. E:=TSQLWhenSQLError(CheckClass(W.Errors[0],TSQLWhenSQLError));
  5689. AssertEquals('Correct SQL Code',1,E.ErrorCode);
  5690. end;
  5691. procedure TTestProcedureStatement.TestWhenGDSCode;
  5692. Var
  5693. W : TSQLWhenStatement;
  5694. E : TSQLWhenGDSError;
  5695. begin
  5696. W:=TSQLWhenStatement(CheckClass(TestStatement('WHEN GDSCODE 1 DO EXIT'),TSQLWhenStatement));
  5697. AssertEquals('Not Any error',False,W.AnyError);
  5698. AssertEquals('1 error code',1,W.Errors.Count);
  5699. CheckClass(W.Statement,TSQLExitStatement);
  5700. E:=TSQLWhenGDSError(CheckClass(W.Errors[0],TSQLWhenGDSError));
  5701. AssertEquals('Correct SQL Code',1,E.GDSErrorNumber);
  5702. end;
  5703. procedure TTestProcedureStatement.TestWhenException;
  5704. Var
  5705. W : TSQLWhenStatement;
  5706. E : TSQLWhenException;
  5707. begin
  5708. W:=TSQLWhenStatement(CheckClass(TestStatement('WHEN EXCEPTION MYE DO EXIT'),TSQLWhenStatement));
  5709. AssertEquals('Not Any error',False,W.AnyError);
  5710. AssertEquals('1 error code',1,W.Errors.Count);
  5711. CheckClass(W.Statement,TSQLExitStatement);
  5712. E:=TSQLWhenException(CheckClass(W.Errors[0],TSQLWhenException));
  5713. AssertIdentifierName('Correct SQL Code','MYE',E.ExceptionName);
  5714. end;
  5715. procedure TTestProcedureStatement.TestWhenExceptionGDS;
  5716. Var
  5717. W : TSQLWhenStatement;
  5718. E : TSQLWhenException;
  5719. G : TSQLWhenGDSError;
  5720. begin
  5721. W:=TSQLWhenStatement(CheckClass(TestStatement('WHEN EXCEPTION MYE, GDSCODE 1 DO EXIT'),TSQLWhenStatement));
  5722. AssertEquals('Not Any error',False,W.AnyError);
  5723. AssertEquals('2 error code',2,W.Errors.Count);
  5724. CheckClass(W.Statement,TSQLExitStatement);
  5725. E:=TSQLWhenException(CheckClass(W.Errors[0],TSQLWhenException));
  5726. AssertIdentifierName('Correct SQL Code','MYE',E.ExceptionName);
  5727. G:=TSQLWhenGDSError(CheckClass(W.Errors[1],TSQLWhenGDSError));
  5728. AssertEquals('Correct SQL Code',1,G.GDSErrorNumber);
  5729. end;
  5730. procedure TTestProcedureStatement.TestWhenAnyBlock;
  5731. Var
  5732. W : TSQLWhenStatement;
  5733. B : TSQLStatementBlock;
  5734. begin
  5735. W:=TSQLWhenStatement(CheckClass(TestStatement('WHEN ANY DO BEGIN EXIT; END'),TSQLWhenStatement));
  5736. AssertEquals('No error codes',0,W.Errors.Count);
  5737. AssertEquals('Any error',True,W.AnyError);
  5738. B:=TSQLStatementBlock(CheckClass(W.Statement,TSQLStatementBlock));
  5739. AssertEquals('One statement',1,B.Statements.Count);
  5740. CheckClass(B.Statements[0],TSQLExitStatement);
  5741. end;
  5742. procedure TTestProcedureStatement.TestWhenErrorAny;
  5743. begin
  5744. TestStatementError('WHEN ANY, EXCEPTION MY DO EXIT');
  5745. end;
  5746. procedure TTestProcedureStatement.TestWhenErrorNoDo;
  5747. begin
  5748. TestStatementError('WHEN ANY EXIT');
  5749. end;
  5750. procedure TTestProcedureStatement.TestWhenErrorExceptionInt;
  5751. begin
  5752. TestStatementError('WHEN EXCEPTION 1 DO EXIT');
  5753. end;
  5754. procedure TTestProcedureStatement.TestWhenErrorExceptionString;
  5755. begin
  5756. TestStatementError('WHEN EXCEPTION ''1'' DO EXIT');
  5757. end;
  5758. procedure TTestProcedureStatement.TestWhenErrorSqlCode;
  5759. begin
  5760. TestStatementError('WHEN SQLCODE A DO EXIT');
  5761. end;
  5762. procedure TTestProcedureStatement.TestWhenErrorGDSCode;
  5763. begin
  5764. TestStatementError('WHEN GDSCODE A DO EXIT');
  5765. end;
  5766. procedure TTestProcedureStatement.TestExecuteStatement;
  5767. Var
  5768. E : TSQLExecuteProcedureStatement;
  5769. begin
  5770. E:=TSQLExecuteProcedureStatement(CheckClass(TestStatement('EXECUTE PROCEDURE A'),TSQLExecuteProcedureStatement));
  5771. AssertIDentifierName('Correct procedure','A',E.ProcedureName);
  5772. end;
  5773. procedure TTestProcedureStatement.TestExecuteStatementReturningValues;
  5774. Var
  5775. E : TSQLExecuteProcedureStatement;
  5776. begin
  5777. E:=TSQLExecuteProcedureStatement(CheckClass(TestStatement('EXECUTE PROCEDURE A RETURNING_VALUES B'),TSQLExecuteProcedureStatement));
  5778. AssertIDentifierName('Correct procedure','A',E.ProcedureName);
  5779. AssertEquals('Returning 1 value',1,E.Returning.Count);
  5780. AssertIDentifierName('Correct return value','B',E.Returning[0]);
  5781. end;
  5782. procedure TTestProcedureStatement.TestExecuteStatementReturningValuesColon;
  5783. Var
  5784. E : TSQLExecuteProcedureStatement;
  5785. begin
  5786. E:=TSQLExecuteProcedureStatement(CheckClass(TestStatement('EXECUTE PROCEDURE A RETURNING_VALUES :B'),TSQLExecuteProcedureStatement));
  5787. AssertIDentifierName('Correct procedure','A',E.ProcedureName);
  5788. AssertEquals('Returning 1 value',1,E.Returning.Count);
  5789. AssertIDentifierName('Correct return value','B',E.Returning[0]);
  5790. end;
  5791. procedure TTestProcedureStatement.TestExecuteStatementReturningValuesBrackets;
  5792. Var
  5793. E : TSQLExecuteProcedureStatement;
  5794. begin
  5795. E:=TSQLExecuteProcedureStatement(CheckClass(TestStatement('EXECUTE PROCEDURE A RETURNING_VALUES (:B)'),TSQLExecuteProcedureStatement));
  5796. AssertIDentifierName('Correct procedure','A',E.ProcedureName);
  5797. AssertEquals('Returning 1 value',1,E.Returning.Count);
  5798. AssertIDentifierName('Correct return value','B',E.Returning[0]);
  5799. end;
  5800. procedure TTestProcedureStatement.TestForSimple;
  5801. Var
  5802. F : TSQLForStatement;
  5803. P : TSQLPostEventStatement;
  5804. begin
  5805. F:=TSQLForStatement(CheckClass(TestStatement('FOR SELECT A FROM B INTO :C DO POST_EVENT C'),TSQLForStatement));
  5806. AssertEquals('Field count',1,F.Select.Fields.Count);
  5807. AssertEquals('Table count',1,F.Select.Tables.Count);
  5808. AssertField(F.Select.Fields[0],'A','');
  5809. AssertTable(F.Select.Tables[0],'B','');
  5810. AssertEquals('Into Fieldlist count',1,F.FieldList.Count);
  5811. AssertIdentifierName('Correct field name','C',F.FieldList[0]);
  5812. P:=TSQLPostEventStatement(CheckClass(F.Statement,TSQLPostEventStatement));
  5813. AssertIdentifierName('Event name','C',P.ColName);
  5814. end;
  5815. procedure TTestProcedureStatement.TestForSimpleNoColon;
  5816. Var
  5817. F : TSQLForStatement;
  5818. P : TSQLPostEventStatement;
  5819. begin
  5820. F:=TSQLForStatement(CheckClass(TestStatement('FOR SELECT A FROM B INTO C DO POST_EVENT C'),TSQLForStatement));
  5821. AssertEquals('Field count',1,F.Select.Fields.Count);
  5822. AssertEquals('Table count',1,F.Select.Tables.Count);
  5823. AssertField(F.Select.Fields[0],'A','');
  5824. AssertTable(F.Select.Tables[0],'B','');
  5825. AssertEquals('Into Fieldlist count',1,F.FieldList.Count);
  5826. AssertIdentifierName('Correct field name','C',F.FieldList[0]);
  5827. P:=TSQLPostEventStatement(CheckClass(F.Statement,TSQLPostEventStatement));
  5828. AssertIdentifierName('Event name','C',P.ColName);
  5829. end;
  5830. procedure TTestProcedureStatement.TestForSimple2fields;
  5831. Var
  5832. F : TSQLForStatement;
  5833. P : TSQLPostEventStatement;
  5834. begin
  5835. F:=TSQLForStatement(CheckClass(TestStatement('FOR SELECT A,B FROM C INTO :D,:E DO POST_EVENT D'),TSQLForStatement));
  5836. AssertEquals('Field count',2,F.Select.Fields.Count);
  5837. AssertEquals('Table count',1,F.Select.Tables.Count);
  5838. AssertField(F.Select.Fields[0],'A','');
  5839. AssertField(F.Select.Fields[1],'B','');
  5840. AssertTable(F.Select.Tables[0],'C','');
  5841. AssertEquals('Into Fieldlist count',2,F.FieldList.Count);
  5842. AssertIdentifierName('Correct field name','D',F.FieldList[0]);
  5843. AssertIdentifierName('Correct field name','E',F.FieldList[1]);
  5844. P:=TSQLPostEventStatement(CheckClass(F.Statement,TSQLPostEventStatement));
  5845. AssertIdentifierName('Event name','D',P.ColName);
  5846. end;
  5847. procedure TTestProcedureStatement.TestForBlock;
  5848. Var
  5849. F : TSQLForStatement;
  5850. P : TSQLPostEventStatement;
  5851. B : TSQLStatementBlock;
  5852. begin
  5853. F:=TSQLForStatement(CheckClass(TestStatement('FOR SELECT A FROM B INTO :C DO BEGIN POST_EVENT C; END'),TSQLForStatement));
  5854. AssertEquals('Field count',1,F.Select.Fields.Count);
  5855. AssertEquals('Table count',1,F.Select.Tables.Count);
  5856. AssertField(F.Select.Fields[0],'A','');
  5857. AssertTable(F.Select.Tables[0],'B','');
  5858. AssertEquals('Into Fieldlist count',1,F.FieldList.Count);
  5859. AssertIdentifierName('Correct field name','C',F.FieldList[0]);
  5860. B:=TSQLStatementBlock(CheckClass(F.Statement,TSQLStatementBlock));
  5861. AssertEquals('One statement',1,B.Statements.Count);
  5862. P:=TSQLPostEventStatement(CheckClass(B.Statements[0],TSQLPostEventStatement));
  5863. AssertIdentifierName('Event name','C',P.ColName);
  5864. end;
  5865. { TTestCreateProcedureParser }
  5866. function TTestCreateProcedureParser.TestCreate(const ASource: String
  5867. ): TSQLCreateProcedureStatement;
  5868. begin
  5869. CreateParser(ASource);
  5870. FToFree:=Parser.Parse;
  5871. Result:=TSQLCreateProcedureStatement(CheckClass(FToFree,TSQLCreateProcedureStatement));
  5872. FSTatement:=Result;
  5873. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  5874. end;
  5875. procedure TTestCreateProcedureParser.TestCreateError(const ASource: String
  5876. );
  5877. begin
  5878. FErrSource:=ASource;
  5879. AssertException(ESQLParser,@TestParseError);
  5880. end;
  5881. procedure TTestCreateProcedureParser.TestEmptyProcedure;
  5882. begin
  5883. TestCreate('CREATE PROCEDURE A AS BEGIN END');
  5884. AssertIdentifierName('Correct procedure name','A',Statement.ObjectName);
  5885. AssertEquals('No arguments',0,Statement.InputVariables.Count);
  5886. AssertEquals('No return values',0,Statement.OutputVariables.Count);
  5887. AssertEquals('No local variables',0,Statement.LocalVariables.Count);
  5888. AssertEquals('No statements',0,Statement.Statements.Count);
  5889. end;
  5890. procedure TTestCreateProcedureParser.TestExitProcedure;
  5891. begin
  5892. TestCreate('CREATE PROCEDURE A AS BEGIN EXIT; END');
  5893. AssertIdentifierName('Correct procedure name','A',Statement.ObjectName);
  5894. AssertEquals('No arguments',0,Statement.InputVariables.Count);
  5895. AssertEquals('No return values',0,Statement.OutputVariables.Count);
  5896. AssertEquals('No local variables',0,Statement.LocalVariables.Count);
  5897. AssertEquals('One statement',1,Statement.Statements.Count);
  5898. CheckClass(Statement.Statements[0],TSQLExitStatement);
  5899. end;
  5900. procedure TTestCreateProcedureParser.TestProcedureOneArgument;
  5901. Var
  5902. P : TSQLProcedureParamDef;
  5903. begin
  5904. TestCreate('CREATE PROCEDURE A (P INT) AS BEGIN END');
  5905. AssertIdentifierName('Correct procedure name','A',Statement.ObjectName);
  5906. AssertEquals('1 arguments',1,Statement.InputVariables.Count);
  5907. P:=TSQLProcedureParamDef(CheckClass(Statement.InputVariables[0],TSQLProcedureParamDef));
  5908. AssertIdentifierName('Correct parameter name','P',P.ParamName);
  5909. AssertNotNull('Have type definition',P.ParamType);
  5910. AssertEquals('Correct type',sdtInteger,P.ParamType.DataType);
  5911. AssertEquals('No return values',0,Statement.OutputVariables.Count);
  5912. AssertEquals('No local variables',0,Statement.LocalVariables.Count);
  5913. AssertEquals('No statements',0,Statement.Statements.Count);
  5914. end;
  5915. procedure TTestCreateProcedureParser.TestProcedureTwoArguments;
  5916. Var
  5917. P : TSQLProcedureParamDef;
  5918. begin
  5919. TestCreate('CREATE PROCEDURE A (P INT,Q CHAR(4)) AS BEGIN END');
  5920. AssertIdentifierName('Correct procedure name','A',Statement.ObjectName);
  5921. AssertEquals('Two arguments',2,Statement.InputVariables.Count);
  5922. P:=TSQLProcedureParamDef(CheckClass(Statement.InputVariables[0],TSQLProcedureParamDef));
  5923. AssertIdentifierName('Correct parameter name','P',P.ParamName);
  5924. AssertNotNull('Have type definition',P.ParamType);
  5925. AssertEquals('Correct type',sdtInteger,P.ParamType.DataType);
  5926. AssertEquals('No return values',0,Statement.OutputVariables.Count);
  5927. P:=TSQLProcedureParamDef(CheckClass(Statement.InputVariables[1],TSQLProcedureParamDef));
  5928. AssertIdentifierName('Correct parameter name','Q',P.ParamName);
  5929. AssertNotNull('Have type definition',P.ParamType);
  5930. AssertEquals('Correct type',sdtChar,P.ParamType.DataType);
  5931. AssertEquals('Correct length',4,P.ParamType.Len);
  5932. //
  5933. AssertEquals('No local variables',0,Statement.LocalVariables.Count);
  5934. AssertEquals('No statements',0,Statement.Statements.Count);
  5935. end;
  5936. procedure TTestCreateProcedureParser.TestProcedureOneReturnValue;
  5937. Var
  5938. P : TSQLProcedureParamDef;
  5939. begin
  5940. TestCreate('CREATE PROCEDURE A RETURNS (P INT) AS BEGIN END');
  5941. AssertIdentifierName('Correct procedure name','A',Statement.ObjectName);
  5942. AssertEquals('1 return value',1,Statement.OutputVariables.Count);
  5943. P:=TSQLProcedureParamDef(CheckClass(Statement.OutputVariables[0],TSQLProcedureParamDef));
  5944. AssertIdentifierName('Correct parameter name','P',P.ParamName);
  5945. AssertNotNull('Have type definition',P.ParamType);
  5946. AssertEquals('Correct type',sdtInteger,P.ParamType.DataType);
  5947. AssertEquals('No input values',0,Statement.InputVariables.Count);
  5948. AssertEquals('No local variables',0,Statement.LocalVariables.Count);
  5949. AssertEquals('No statements',0,Statement.Statements.Count);
  5950. end;
  5951. procedure TTestCreateProcedureParser.TestProcedureTwoReturnValues;
  5952. Var
  5953. P : TSQLProcedureParamDef;
  5954. begin
  5955. TestCreate('CREATE PROCEDURE A RETURNS (P INT, Q CHAR(5)) AS BEGIN END');
  5956. AssertIdentifierName('Correct procedure name','A',Statement.ObjectName);
  5957. AssertEquals('2 return values',2,Statement.OutputVariables.Count);
  5958. P:=TSQLProcedureParamDef(CheckClass(Statement.OutputVariables[0],TSQLProcedureParamDef));
  5959. AssertIdentifierName('Correct parameter name','P',P.ParamName);
  5960. AssertNotNull('Have type definition',P.ParamType);
  5961. AssertEquals('Correct type',sdtInteger,P.ParamType.DataType);
  5962. P:=TSQLProcedureParamDef(CheckClass(Statement.OutputVariables[1],TSQLProcedureParamDef));
  5963. AssertIdentifierName('Correct parameter name','Q',P.ParamName);
  5964. AssertNotNull('Have type definition',P.ParamType);
  5965. AssertEquals('Correct type',sdtChar,P.ParamType.DataType);
  5966. AssertEquals('Correct length',5,P.ParamType.Len);
  5967. AssertEquals('No input values',0,Statement.InputVariables.Count);
  5968. AssertEquals('No local variables',0,Statement.LocalVariables.Count);
  5969. AssertEquals('No statements',0,Statement.Statements.Count);
  5970. end;
  5971. procedure TTestCreateProcedureParser.TestProcedureOneLocalVariable;
  5972. Var
  5973. P : TSQLProcedureParamDef;
  5974. begin
  5975. TestCreate('CREATE PROCEDURE A AS DECLARE VARIABLE P INT; BEGIN END');
  5976. AssertIdentifierName('Correcte procedure naam','A',Statement.ObjectName);
  5977. AssertEquals('0 return values',0,Statement.OutputVariables.Count);
  5978. AssertEquals('1 local variable',1,Statement.LocalVariables.Count);
  5979. P:=TSQLProcedureParamDef(CheckClass(Statement.LocalVariables[0],TSQLProcedureParamDef));
  5980. AssertIdentifierName('Correct parameter name','P',P.ParamName);
  5981. AssertNotNull('Have type definition',P.ParamType);
  5982. AssertEquals('Correct type',sdtInteger,P.ParamType.DataType);
  5983. AssertEquals('No input values',0,Statement.InputVariables.Count);
  5984. AssertEquals('No statements',0,Statement.Statements.Count);
  5985. end;
  5986. procedure TTestCreateProcedureParser.TestProcedureTwoLocalVariable;
  5987. Var
  5988. P : TSQLProcedureParamDef;
  5989. begin
  5990. TestCreate('CREATE PROCEDURE A AS DECLARE VARIABLE P INT; DECLARE VARIABLE Q CHAR(5); BEGIN END');
  5991. AssertIdentifierName('Correcte procedure naam','A',Statement.ObjectName);
  5992. AssertEquals('0 return values',0,Statement.OutputVariables.Count);
  5993. AssertEquals('2 local variable',2,Statement.LocalVariables.Count);
  5994. P:=TSQLProcedureParamDef(CheckClass(Statement.LocalVariables[0],TSQLProcedureParamDef));
  5995. AssertIdentifierName('Correct parameter name','P',P.ParamName);
  5996. AssertNotNull('Have type definition',P.ParamType);
  5997. AssertEquals('Correct type',sdtInteger,P.ParamType.DataType);
  5998. P:=TSQLProcedureParamDef(CheckClass(Statement.LocalVariables[1],TSQLProcedureParamDef));
  5999. AssertIdentifierName('Correct parameter name','Q',P.ParamName);
  6000. AssertNotNull('Have type definition',P.ParamType);
  6001. AssertEquals('Correct type',sdtChar,P.ParamType.DataType);
  6002. AssertEquals('Correct length',5,P.ParamType.Len);
  6003. AssertEquals('No input values',0,Statement.InputVariables.Count);
  6004. AssertEquals('No statements',0,Statement.Statements.Count);
  6005. end;
  6006. procedure TTestCreateProcedureParser.TestProcedureInputOutputLocal;
  6007. Var
  6008. P : TSQLProcedureParamDef;
  6009. begin
  6010. TestCreate('CREATE PROCEDURE A (P INT) RETURNS (Q CHAR(5)) AS DECLARE VARIABLE R VARCHAR(5); BEGIN END');
  6011. AssertIdentifierName('Correcte procedure naam','A',Statement.ObjectName);
  6012. // Input
  6013. AssertEquals('1 input value',1,Statement.InputVariables.Count);
  6014. P:=TSQLProcedureParamDef(CheckClass(Statement.InputVariables[0],TSQLProcedureParamDef));
  6015. AssertIdentifierName('Correct parameter name','P',P.ParamName);
  6016. AssertNotNull('Have type definition',P.ParamType);
  6017. AssertEquals('Correct type',sdtInteger,P.ParamType.DataType);
  6018. // Output
  6019. AssertEquals('1 return values',1,Statement.OutputVariables.Count);
  6020. P:=TSQLProcedureParamDef(CheckClass(Statement.OutputVariables[0],TSQLProcedureParamDef));
  6021. AssertIdentifierName('Correct parameter name','Q',P.ParamName);
  6022. AssertNotNull('Have type definition',P.ParamType);
  6023. AssertEquals('Correct type',sdtChar,P.ParamType.DataType);
  6024. AssertEquals('Correct length',5,P.ParamType.Len);
  6025. // Local
  6026. AssertEquals('1 local variable',1,Statement.LocalVariables.Count);
  6027. P:=TSQLProcedureParamDef(CheckClass(Statement.LocalVariables[0],TSQLProcedureParamDef));
  6028. AssertIdentifierName('Correct parameter name','R',P.ParamName);
  6029. AssertNotNull('Have type definition',P.ParamType);
  6030. AssertEquals('Correct type',sdtvarChar,P.ParamType.DataType);
  6031. AssertEquals('Correct length',5,P.ParamType.Len);
  6032. AssertEquals('No statements',0,Statement.Statements.Count);
  6033. end;
  6034. { TTestCreateTriggerParser }
  6035. function TTestCreateTriggerParser.TestCreate(const ASource: String
  6036. ): TSQLCreateTriggerStatement;
  6037. begin
  6038. CreateParser(ASource);
  6039. FToFree:=Parser.Parse;
  6040. Result:=TSQLCreateTriggerStatement(CheckClass(FToFree,TSQLCreateTriggerStatement));
  6041. FSTatement:=Result;
  6042. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  6043. end;
  6044. function TTestCreateTriggerParser.TestAlter(const ASource: String
  6045. ): TSQLAlterTriggerStatement;
  6046. begin
  6047. CreateParser(ASource);
  6048. FToFree:=Parser.Parse;
  6049. Result:=TSQLAlterTriggerStatement(CheckClass(FToFree,TSQLAlterTriggerStatement));
  6050. FSTatement:=Result;
  6051. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  6052. end;
  6053. procedure TTestCreateTriggerParser.TestCreateError(const ASource: String);
  6054. begin
  6055. FErrSource:=ASource;
  6056. AssertException(ESQLParser,@TestParseError);
  6057. end;
  6058. procedure TTestCreateTriggerParser.TestEmptyTrigger;
  6059. begin
  6060. TestCreate('CREATE TRIGGER A FOR B BEFORE UPDATE AS BEGIN END');
  6061. AssertIdentifierName('Correct trigger name','A',Statement.ObjectName);
  6062. AssertIdentifierName('Correct table','B',Statement.TableName);
  6063. AssertEquals('No variables',0,Statement.LocalVariables.Count);
  6064. AssertEquals('No Statements',0,Statement.Statements.Count);
  6065. AssertEquals('No position',0,Statement.Position);
  6066. AssertEquals('No active/inactive',tsNone,Statement.State);
  6067. AssertEquals('Before moment',tmBefore,Statement.Moment);
  6068. AssertEquals('Update operation',[toUpdate],Statement.Operations);
  6069. end;
  6070. procedure TTestCreateTriggerParser.TestExitTrigger;
  6071. begin
  6072. TestCreate('CREATE TRIGGER A FOR B BEFORE UPDATE AS BEGIN EXIT; END');
  6073. AssertIdentifierName('Correct trigger name','A',Statement.ObjectName);
  6074. AssertIdentifierName('Correct table','B',Statement.TableName);
  6075. AssertEquals('No variables',0,Statement.LocalVariables.Count);
  6076. AssertEquals('1 Statements',1,Statement.Statements.Count);
  6077. AssertEquals('No position',0,Statement.Position);
  6078. AssertEquals('No active/inactive',tsNone,Statement.State);
  6079. AssertEquals('Before moment',tmBefore,Statement.Moment);
  6080. AssertEquals('Update operation',[toUpdate],Statement.Operations);
  6081. CheckClass(Statement.Statements[0],TSQLExitStatement);
  6082. end;
  6083. procedure TTestCreateTriggerParser.TestEmptyTriggerAfterUpdate;
  6084. begin
  6085. TestCreate('CREATE TRIGGER A FOR B AFTER UPDATE AS BEGIN END');
  6086. AssertIdentifierName('Correct trigger name','A',Statement.ObjectName);
  6087. AssertIdentifierName('Correct table','B',Statement.TableName);
  6088. AssertEquals('No variables',0,Statement.LocalVariables.Count);
  6089. AssertEquals('No Statements',0,Statement.Statements.Count);
  6090. AssertEquals('No position',0,Statement.Position);
  6091. AssertEquals('No active/inactive',tsNone,Statement.State);
  6092. AssertEquals('Before moment',tmAfter,Statement.Moment);
  6093. AssertEquals('Update operation',[toUpdate],Statement.Operations);
  6094. end;
  6095. procedure TTestCreateTriggerParser.TestEmptyTriggerBeforeDelete;
  6096. begin
  6097. TestCreate('CREATE TRIGGER A FOR B BEFORE DELETE AS BEGIN END');
  6098. AssertIdentifierName('Correct trigger name','A',Statement.ObjectName);
  6099. AssertIdentifierName('Correct table','B',Statement.TableName);
  6100. AssertEquals('No variables',0,Statement.LocalVariables.Count);
  6101. AssertEquals('No Statements',0,Statement.Statements.Count);
  6102. AssertEquals('No position',0,Statement.Position);
  6103. AssertEquals('No active/inactive',tsNone,Statement.State);
  6104. AssertEquals('Before moment',tmBefore,Statement.Moment);
  6105. AssertEquals('Delete operation',[toDelete],Statement.Operations);
  6106. end;
  6107. procedure TTestCreateTriggerParser.TestEmptyTriggerBeforeInsert;
  6108. begin
  6109. TestCreate('CREATE TRIGGER A FOR B BEFORE INSERT AS BEGIN END');
  6110. AssertIdentifierName('Correct trigger name','A',Statement.ObjectName);
  6111. AssertIdentifierName('Correct table','B',Statement.TableName);
  6112. AssertEquals('No variables',0,Statement.LocalVariables.Count);
  6113. AssertEquals('No Statements',0,Statement.Statements.Count);
  6114. AssertEquals('No position',0,Statement.Position);
  6115. AssertEquals('No active/inactive',tsNone,Statement.State);
  6116. AssertEquals('Before moment',tmBefore,Statement.Moment);
  6117. AssertEquals('Insert operation',[toInsert],Statement.Operations);
  6118. end;
  6119. procedure TTestCreateTriggerParser.TestEmptyTriggerBeforeInsertPosition1;
  6120. begin
  6121. TestCreate('CREATE TRIGGER A FOR B BEFORE INSERT POSITION 1 AS BEGIN END');
  6122. AssertIdentifierName('Correct trigger name','A',Statement.ObjectName);
  6123. AssertIdentifierName('Correct table','B',Statement.TableName);
  6124. AssertEquals('No variables',0,Statement.LocalVariables.Count);
  6125. AssertEquals('No Statements',0,Statement.Statements.Count);
  6126. AssertEquals('position 1',1,Statement.Position);
  6127. AssertEquals('No active/inactive',tsNone,Statement.State);
  6128. AssertEquals('Before moment',tmBefore,Statement.Moment);
  6129. AssertEquals('Insert operation',[toInsert],Statement.Operations);
  6130. end;
  6131. procedure TTestCreateTriggerParser.TestEmptyTriggerBeforeInsertPosition1inActive;
  6132. begin
  6133. TestCreate('CREATE TRIGGER A FOR B INACTIVE BEFORE INSERT POSITION 1 AS BEGIN END');
  6134. AssertIdentifierName('Correct trigger name','A',Statement.ObjectName);
  6135. AssertIdentifierName('Correct table','B',Statement.TableName);
  6136. AssertEquals('No variables',0,Statement.LocalVariables.Count);
  6137. AssertEquals('No Statements',0,Statement.Statements.Count);
  6138. AssertEquals('position 1',1,Statement.Position);
  6139. AssertEquals('inactive',tsInactive,Statement.State);
  6140. AssertEquals('Before moment',tmBefore,Statement.Moment);
  6141. AssertEquals('Insert operation',[toInsert],Statement.Operations);
  6142. end;
  6143. procedure TTestCreateTriggerParser.TestEmptyTriggerBeforeInsertPosition1Active;
  6144. begin
  6145. TestCreate('CREATE TRIGGER A FOR B ACTIVE BEFORE INSERT POSITION 1 AS BEGIN END');
  6146. AssertIdentifierName('Correct trigger name','A',Statement.ObjectName);
  6147. AssertIdentifierName('Correct table','B',Statement.TableName);
  6148. AssertEquals('No variables',0,Statement.LocalVariables.Count);
  6149. AssertEquals('No Statements',0,Statement.Statements.Count);
  6150. AssertEquals('position 1',1,Statement.Position);
  6151. AssertEquals('Active',tsActive,Statement.State);
  6152. AssertEquals('Before moment',tmBefore,Statement.Moment);
  6153. AssertEquals('Insert operation',[toInsert],Statement.Operations);
  6154. end;
  6155. procedure TTestCreateTriggerParser.TestTriggerOneLocalVariable;
  6156. Var
  6157. P : TSQLProcedureParamDef;
  6158. begin
  6159. TestCreate('CREATE TRIGGER A FOR B ACTIVE BEFORE INSERT POSITION 1 AS DECLARE VARIABLE P INT; BEGIN END');
  6160. AssertIdentifierName('Correcte procedure naam','A',Statement.ObjectName);
  6161. AssertIdentifierName('Correct table','B',Statement.TableName);
  6162. AssertEquals('No Statements',0,Statement.Statements.Count);
  6163. AssertEquals('position 1',1,Statement.Position);
  6164. AssertEquals('Active',tsActive,Statement.State);
  6165. AssertEquals('Before moment',tmBefore,Statement.Moment);
  6166. AssertEquals('Insert operation',[toInsert],Statement.Operations);
  6167. AssertEquals('1 local variable',1,Statement.LocalVariables.Count);
  6168. P:=TSQLProcedureParamDef(CheckClass(Statement.LocalVariables[0],TSQLProcedureParamDef));
  6169. AssertIdentifierName('Correct parameter name','P',P.ParamName);
  6170. AssertNotNull('Have type definition',P.ParamType);
  6171. AssertEquals('Correct type',sdtInteger,P.ParamType.DataType);
  6172. end;
  6173. procedure TTestCreateTriggerParser.TestTriggerTwoLocalVariables;
  6174. Var
  6175. P : TSQLProcedureParamDef;
  6176. begin
  6177. TestCreate('CREATE TRIGGER A FOR B ACTIVE BEFORE INSERT POSITION 1 AS DECLARE VARIABLE P INT; DECLARE VARIABLE Q INT; BEGIN END');
  6178. AssertIdentifierName('Correcte procedure naam','A',Statement.ObjectName);
  6179. AssertIdentifierName('Correct table','B',Statement.TableName);
  6180. AssertEquals('No Statements',0,Statement.Statements.Count);
  6181. AssertEquals('position 1',1,Statement.Position);
  6182. AssertEquals('Active',tsActive,Statement.State);
  6183. AssertEquals('Before moment',tmBefore,Statement.Moment);
  6184. AssertEquals('Insert operation',[toInsert],Statement.Operations);
  6185. AssertEquals('2 local variables',2,Statement.LocalVariables.Count);
  6186. P:=TSQLProcedureParamDef(CheckClass(Statement.LocalVariables[0],TSQLProcedureParamDef));
  6187. AssertIdentifierName('Correct parameter name','P',P.ParamName);
  6188. AssertNotNull('Have type definition',P.ParamType);
  6189. AssertEquals('Correct type',sdtInteger,P.ParamType.DataType);
  6190. P:=TSQLProcedureParamDef(CheckClass(Statement.LocalVariables[1],TSQLProcedureParamDef));
  6191. AssertIdentifierName('Correct parameter name','Q',P.ParamName);
  6192. AssertNotNull('Have type definition',P.ParamType);
  6193. AssertEquals('Correct type',sdtInteger,P.ParamType.DataType);
  6194. end;
  6195. procedure TTestCreateTriggerParser.TestAlterTrigger;
  6196. begin
  6197. TestAlter('ALTER TRIGGER A BEFORE UPDATE AS BEGIN END');
  6198. AssertIdentifierName('Correct trigger name','A',Statement.ObjectName);
  6199. AssertNull('Correct table',Statement.TableName);
  6200. AssertEquals('No variables',0,Statement.LocalVariables.Count);
  6201. AssertEquals('No Statements',0,Statement.Statements.Count);
  6202. AssertEquals('No position',0,Statement.Position);
  6203. AssertEquals('No active/inactive',tsNone,Statement.State);
  6204. AssertEquals('Before moment',tmBefore,Statement.Moment);
  6205. AssertEquals('Update operation',[toUpdate],Statement.Operations);
  6206. end;
  6207. { TTestDeclareExternalFunctionParser }
  6208. function TTestDeclareExternalFunctionParser.TestCreate(const ASource: String
  6209. ): TSQLDeclareExternalFunctionStatement;
  6210. begin
  6211. CreateParser(ASource);
  6212. FToFree:=Parser.Parse;
  6213. Result:=TSQLDeclareExternalFunctionStatement(CheckClass(FToFree,TSQLDeclareExternalFunctionStatement));
  6214. FSTatement:=Result;
  6215. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  6216. end;
  6217. procedure TTestDeclareExternalFunctionParser.TestCreateError(
  6218. const ASource: String);
  6219. begin
  6220. FErrSource:=ASource;
  6221. AssertException(ESQLParser,@TestParseError);
  6222. end;
  6223. procedure TTestDeclareExternalFunctionParser.TestEmptyfunction;
  6224. begin
  6225. TestCreate('DECLARE EXTERNAL FUNCTION A RETURNS INT ENTRY_POINT ''A'' MODULE_NAME ''B''');
  6226. AssertIdentifierName('Correct function','A',Statement.ObjectName);
  6227. AssertEquals('Correct entry point','A',Statement.EntryPoint);
  6228. AssertEquals('Correct module name','B',Statement.ModuleName);
  6229. AssertEquals('No arguments',0,Statement.Arguments.Count);
  6230. AssertNotNull('Have return type',Statement.ReturnType);
  6231. AssertEquals('No FreeIt',False,Statement.FreeIt);
  6232. AssertEquals('Correct return type',sdtInteger,Statement.ReturnType.DataType);
  6233. end;
  6234. procedure TTestDeclareExternalFunctionParser.TestEmptyfunctionByValue;
  6235. begin
  6236. TestCreate('DECLARE EXTERNAL FUNCTION A RETURNS INT BY VALUE ENTRY_POINT ''A'' MODULE_NAME ''B''');
  6237. AssertIdentifierName('Correct function','A',Statement.ObjectName);
  6238. AssertEquals('Correct entry point','A',Statement.EntryPoint);
  6239. AssertEquals('Correct module name','B',Statement.ModuleName);
  6240. AssertEquals('No arguments',0,Statement.Arguments.Count);
  6241. AssertNotNull('Have return type',Statement.ReturnType);
  6242. AssertEquals('No FreeIt',False,Statement.FreeIt);
  6243. AssertEquals('Correct return type',sdtInteger,Statement.ReturnType.DataType);
  6244. AssertEquals('By Value',True,Statement.ReturnType.ByValue);
  6245. end;
  6246. procedure TTestDeclareExternalFunctionParser.TestCStringfunction;
  6247. begin
  6248. TestCreate('DECLARE EXTERNAL FUNCTION A RETURNS CSTRING (50) ENTRY_POINT ''A'' MODULE_NAME ''B''');
  6249. AssertIdentifierName('Correct function','A',Statement.ObjectName);
  6250. AssertEquals('Correct entry point','A',Statement.EntryPoint);
  6251. AssertEquals('Correct module name','B',Statement.ModuleName);
  6252. AssertEquals('No arguments',0,Statement.Arguments.Count);
  6253. AssertNotNull('Have return type',Statement.ReturnType);
  6254. AssertEquals('No FreeIt',False,Statement.FreeIt);
  6255. AssertEquals('Correct return type',sdtCstring,Statement.ReturnType.DataType);
  6256. AssertEquals('Correct return length',50,Statement.ReturnType.Len);
  6257. end;
  6258. procedure TTestDeclareExternalFunctionParser.TestCStringFreeItfunction;
  6259. begin
  6260. TestCreate('DECLARE EXTERNAL FUNCTION A RETURNS CSTRING (50) FREE_IT ENTRY_POINT ''A'' MODULE_NAME ''B''');
  6261. AssertIdentifierName('Correct function','A',Statement.ObjectName);
  6262. AssertEquals('Correct entry point','A',Statement.EntryPoint);
  6263. AssertEquals('Correct module name','B',Statement.ModuleName);
  6264. AssertEquals('No arguments',0,Statement.Arguments.Count);
  6265. AssertNotNull('Have return type',Statement.ReturnType);
  6266. AssertEquals('FreeIt',True,Statement.FreeIt);
  6267. AssertEquals('Correct return type',sdtCstring,Statement.ReturnType.DataType);
  6268. AssertEquals('Correct return length',50,Statement.ReturnType.Len);
  6269. end;
  6270. procedure TTestDeclareExternalFunctionParser.TestOneArgumentFunction;
  6271. Var
  6272. T : TSQLTypeDefinition;
  6273. begin
  6274. TestCreate('DECLARE EXTERNAL FUNCTION A INT RETURNS INT ENTRY_POINT ''A'' MODULE_NAME ''B''');
  6275. AssertIdentifierName('Correct function','A',Statement.ObjectName);
  6276. AssertEquals('Correct entry point','A',Statement.EntryPoint);
  6277. AssertEquals('Correct module name','B',Statement.ModuleName);
  6278. AssertEquals('1 argument',1,Statement.Arguments.Count);
  6279. T:=TSQLTypeDefinition(CheckClass(Statement.Arguments[0],TSQLTypeDefinition));
  6280. AssertEquals('Correct return type',sdtInteger,T.DataType);
  6281. AssertNotNull('Have return type',Statement.ReturnType);
  6282. AssertEquals('No FreeIt',False,Statement.FreeIt);
  6283. AssertEquals('Correct return type',sdtInteger,Statement.ReturnType.DataType);
  6284. end;
  6285. procedure TTestDeclareExternalFunctionParser.TestTwoArgumentsFunction;
  6286. Var
  6287. T : TSQLTypeDefinition;
  6288. begin
  6289. TestCreate('DECLARE EXTERNAL FUNCTION A INT, CSTRING(10) RETURNS INT ENTRY_POINT ''A'' MODULE_NAME ''B''');
  6290. AssertIdentifierName('Correct function','A',Statement.ObjectName);
  6291. AssertEquals('Correct entry point','A',Statement.EntryPoint);
  6292. AssertEquals('Correct module name','B',Statement.ModuleName);
  6293. AssertEquals('2 arguments',2,Statement.Arguments.Count);
  6294. T:=TSQLTypeDefinition(CheckClass(Statement.Arguments[0],TSQLTypeDefinition));
  6295. AssertEquals('Correct argument type',sdtInteger,T.DataType);
  6296. T:=TSQLTypeDefinition(CheckClass(Statement.Arguments[1],TSQLTypeDefinition));
  6297. AssertEquals('Correct return type',sdtCstring,T.DataType);
  6298. AssertEquals('Correct argument length',10,T.Len);
  6299. AssertNotNull('Have return type',Statement.ReturnType);
  6300. AssertEquals('No FreeIt',False,Statement.FreeIt);
  6301. AssertEquals('Correct return type',sdtInteger,Statement.ReturnType.DataType);
  6302. end;
  6303. { TTestGrantParser }
  6304. function TTestGrantParser.TestGrant(const ASource: String): TSQLGrantStatement;
  6305. begin
  6306. CreateParser(ASource);
  6307. FToFree:=Parser.Parse;
  6308. If not (FToFree is TSQLGrantStatement) then
  6309. Fail(Format('Wrong parse result class. Expected TSQLGrantStatement, got %s',[FTofree.ClassName]));
  6310. Result:=TSQLGrantStatement(Ftofree);
  6311. FSTatement:=Result;
  6312. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  6313. end;
  6314. procedure TTestGrantParser.TestGrantError(const ASource: String);
  6315. begin
  6316. FErrSource:=ASource;
  6317. AssertException(ESQLParser,@TestParseError);
  6318. end;
  6319. procedure TTestGrantParser.TestSimple;
  6320. Var
  6321. t : TSQLTableGrantStatement;
  6322. G : TSQLUSerGrantee;
  6323. begin
  6324. TestGrant('GRANT SELECT ON A TO B');
  6325. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6326. AssertIdentifierName('Table name','A',T.TableName);
  6327. AssertEquals('One grantee', 1,T.Grantees.Count);
  6328. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6329. AssertEquals('Grantee B','B',G.Name);
  6330. AssertEquals('One permission',1,T.Privileges.Count);
  6331. CheckClass(T.Privileges[0],TSQLSelectPrivilege);
  6332. AssertEquals('No grant option',False,T.GrantOption);
  6333. end;
  6334. procedure TTestGrantParser.Test2Operations;
  6335. Var
  6336. t : TSQLTableGrantStatement;
  6337. G : TSQLUSerGrantee;
  6338. begin
  6339. TestGrant('GRANT SELECT,INSERT ON A TO B');
  6340. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6341. AssertIdentifierName('Table name','A',T.TableName);
  6342. AssertEquals('One grantee', 1,T.Grantees.Count);
  6343. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6344. AssertEquals('Grantee B','B',G.Name);
  6345. AssertEquals('Two permissions',2,T.Privileges.Count);
  6346. CheckClass(T.Privileges[0],TSQLSelectPrivilege);
  6347. CheckClass(T.Privileges[1],TSQLINSERTPrivilege);
  6348. AssertEquals('No grant option',False,T.GrantOption);
  6349. end;
  6350. procedure TTestGrantParser.TestDeletePrivilege;
  6351. Var
  6352. t : TSQLTableGrantStatement;
  6353. G : TSQLUSerGrantee;
  6354. begin
  6355. TestGrant('GRANT DELETE ON A TO B');
  6356. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6357. AssertIdentifierName('Table name','A',T.TableName);
  6358. AssertEquals('One grantee', 1,T.Grantees.Count);
  6359. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6360. AssertEquals('Grantee B','B',G.Name);
  6361. AssertEquals('One permission',1,T.Privileges.Count);
  6362. CheckClass(T.Privileges[0],TSQLDeletePrivilege);
  6363. AssertEquals('No grant option',False,T.GrantOption);
  6364. end;
  6365. procedure TTestGrantParser.TestUpdatePrivilege;
  6366. Var
  6367. t : TSQLTableGrantStatement;
  6368. G : TSQLUSerGrantee;
  6369. begin
  6370. TestGrant('GRANT UPDATE ON A TO B');
  6371. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6372. AssertIdentifierName('Table name','A',T.TableName);
  6373. AssertEquals('One grantee', 1,T.Grantees.Count);
  6374. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6375. AssertEquals('Grantee B','B',G.Name);
  6376. AssertEquals('One permission',1,T.Privileges.Count);
  6377. CheckClass(T.Privileges[0],TSQLUPDATEPrivilege);
  6378. AssertEquals('No grant option',False,T.GrantOption);
  6379. end;
  6380. procedure TTestGrantParser.TestInsertPrivilege;
  6381. Var
  6382. t : TSQLTableGrantStatement;
  6383. G : TSQLUSerGrantee;
  6384. begin
  6385. TestGrant('GRANT INSERT ON A TO B');
  6386. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6387. AssertIdentifierName('Table name','A',T.TableName);
  6388. AssertEquals('One grantee', 1,T.Grantees.Count);
  6389. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6390. AssertEquals('Grantee B','B',G.Name);
  6391. AssertEquals('One permission',1,T.Privileges.Count);
  6392. CheckClass(T.Privileges[0],TSQLInsertPrivilege);
  6393. AssertEquals('No grant option',False,T.GrantOption);
  6394. end;
  6395. procedure TTestGrantParser.TestReferencePrivilege;
  6396. Var
  6397. t : TSQLTableGrantStatement;
  6398. G : TSQLUSerGrantee;
  6399. begin
  6400. TestGrant('GRANT REFERENCES ON A TO B');
  6401. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6402. AssertIdentifierName('Table name','A',T.TableName);
  6403. AssertEquals('One grantee', 1,T.Grantees.Count);
  6404. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6405. AssertEquals('Grantee B','B',G.Name);
  6406. AssertEquals('One permission',1,T.Privileges.Count);
  6407. CheckClass(T.Privileges[0],TSQLReferencePrivilege);
  6408. AssertEquals('No grant option',False,T.GrantOption);
  6409. end;
  6410. procedure TTestGrantParser.TestAllPrivileges;
  6411. Var
  6412. t : TSQLTableGrantStatement;
  6413. G : TSQLUSerGrantee;
  6414. begin
  6415. TestGrant('GRANT ALL ON A TO B');
  6416. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6417. AssertIdentifierName('Table name','A',T.TableName);
  6418. AssertEquals('One grantee', 1,T.Grantees.Count);
  6419. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6420. AssertEquals('Grantee B','B',G.Name);
  6421. AssertEquals('One permission',1,T.Privileges.Count);
  6422. CheckClass(T.Privileges[0],TSQLAllPrivilege);
  6423. AssertEquals('No grant option',False,T.GrantOption);
  6424. end;
  6425. procedure TTestGrantParser.TestAllPrivileges2;
  6426. Var
  6427. t : TSQLTableGrantStatement;
  6428. G : TSQLUSerGrantee;
  6429. begin
  6430. TestGrant('GRANT ALL PRIVILEGES ON A TO B');
  6431. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6432. AssertIdentifierName('Table name','A',T.TableName);
  6433. AssertEquals('One grantee', 1,T.Grantees.Count);
  6434. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6435. AssertEquals('Grantee B','B',G.Name);
  6436. AssertEquals('One permission',1,T.Privileges.Count);
  6437. CheckClass(T.Privileges[0],TSQLAllPrivilege);
  6438. AssertEquals('No grant option',False,T.GrantOption);
  6439. end;
  6440. procedure TTestGrantParser.TestUpdateColPrivilege;
  6441. Var
  6442. t : TSQLTableGrantStatement;
  6443. G : TSQLUSerGrantee;
  6444. U : TSQLUPDATEPrivilege;
  6445. begin
  6446. TestGrant('GRANT UPDATE (C) ON A TO B');
  6447. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6448. AssertIdentifierName('Table name','A',T.TableName);
  6449. AssertEquals('One grantee', 1,T.Grantees.Count);
  6450. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6451. AssertEquals('Grantee B','B',G.Name);
  6452. AssertEquals('One permission',1,T.Privileges.Count);
  6453. U:=TSQLUPDATEPrivilege(CheckClass(T.Privileges[0],TSQLUPDATEPrivilege));
  6454. AssertEquals('1 column',1,U.Columns.Count);
  6455. AssertIdentifierName('Column C','C',U.Columns[0]);
  6456. AssertEquals('No grant option',False,T.GrantOption);
  6457. end;
  6458. procedure TTestGrantParser.TestUpdate2ColsPrivilege;
  6459. Var
  6460. t : TSQLTableGrantStatement;
  6461. G : TSQLUSerGrantee;
  6462. U : TSQLUPDATEPrivilege;
  6463. begin
  6464. TestGrant('GRANT UPDATE (C,D) ON A TO B');
  6465. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6466. AssertIdentifierName('Table name','A',T.TableName);
  6467. AssertEquals('One grantee', 1,T.Grantees.Count);
  6468. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6469. AssertEquals('Grantee B','B',G.Name);
  6470. AssertEquals('One permission',1,T.Privileges.Count);
  6471. U:=TSQLUPDATEPrivilege(CheckClass(T.Privileges[0],TSQLUPDATEPrivilege));
  6472. AssertEquals('2 column',2,U.Columns.Count);
  6473. AssertIdentifierName('Column C','C',U.Columns[0]);
  6474. AssertIdentifierName('Column D','D',U.Columns[1]);
  6475. AssertEquals('No grant option',False,T.GrantOption);
  6476. end;
  6477. procedure TTestGrantParser.TestReferenceColPrivilege;
  6478. Var
  6479. t : TSQLTableGrantStatement;
  6480. G : TSQLUSerGrantee;
  6481. U : TSQLReferencePrivilege;
  6482. begin
  6483. TestGrant('GRANT REFERENCES (C) ON A TO B');
  6484. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6485. AssertIdentifierName('Table name','A',T.TableName);
  6486. AssertEquals('One grantee', 1,T.Grantees.Count);
  6487. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6488. AssertEquals('Grantee B','B',G.Name);
  6489. AssertEquals('One permission',1,T.Privileges.Count);
  6490. U:=TSQLReferencePrivilege(CheckClass(T.Privileges[0],TSQLReferencePrivilege));
  6491. AssertEquals('1 column',1,U.Columns.Count);
  6492. AssertIdentifierName('Column C','C',U.Columns[0]);
  6493. AssertEquals('No grant option',False,T.GrantOption);
  6494. end;
  6495. procedure TTestGrantParser.TestReference2ColsPrivilege;
  6496. Var
  6497. t : TSQLTableGrantStatement;
  6498. G : TSQLUSerGrantee;
  6499. U : TSQLReferencePrivilege;
  6500. begin
  6501. TestGrant('GRANT REFERENCES (C,D) ON A TO B');
  6502. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6503. AssertIdentifierName('Table name','A',T.TableName);
  6504. AssertEquals('One grantee', 1,T.Grantees.Count);
  6505. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6506. AssertEquals('Grantee B','B',G.Name);
  6507. AssertEquals('One permission',1,T.Privileges.Count);
  6508. U:=TSQLReferencePrivilege(CheckClass(T.Privileges[0],TSQLReferencePrivilege));
  6509. AssertEquals('2 column',2,U.Columns.Count);
  6510. AssertIdentifierName('Column C','C',U.Columns[0]);
  6511. AssertIdentifierName('Column D','D',U.Columns[1]);
  6512. AssertEquals('No grant option',False,T.GrantOption);
  6513. end;
  6514. procedure TTestGrantParser.TestUserPrivilege;
  6515. Var
  6516. t : TSQLTableGrantStatement;
  6517. G : TSQLUSerGrantee;
  6518. begin
  6519. TestGrant('GRANT SELECT ON A TO USER B');
  6520. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6521. AssertIdentifierName('Table name','A',T.TableName);
  6522. AssertEquals('One grantee', 1,T.Grantees.Count);
  6523. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6524. AssertEquals('Grantee B','B',G.Name);
  6525. AssertEquals('One permission',1,T.Privileges.Count);
  6526. CheckClass(T.Privileges[0],TSQLSelectPrivilege);
  6527. AssertEquals('No grant option',False,T.GrantOption);
  6528. end;
  6529. procedure TTestGrantParser.TestUserPrivilegeWithGrant;
  6530. Var
  6531. t : TSQLTableGrantStatement;
  6532. G : TSQLUSerGrantee;
  6533. begin
  6534. TestGrant('GRANT SELECT ON A TO USER B WITH GRANT OPTION');
  6535. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6536. AssertIdentifierName('Table name','A',T.TableName);
  6537. AssertEquals('One grantee', 1,T.Grantees.Count);
  6538. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6539. AssertEquals('Grantee B','B',G.Name);
  6540. AssertEquals('One permission',1,T.Privileges.Count);
  6541. CheckClass(T.Privileges[0],TSQLSelectPrivilege);
  6542. AssertEquals('With grant option',True,T.GrantOption);
  6543. end;
  6544. procedure TTestGrantParser.TestGroupPrivilege;
  6545. Var
  6546. t : TSQLTableGrantStatement;
  6547. G : TSQLGroupGrantee;
  6548. begin
  6549. TestGrant('GRANT SELECT ON A TO GROUP B');
  6550. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6551. AssertIdentifierName('Table name','A',T.TableName);
  6552. AssertEquals('One grantee', 1,T.Grantees.Count);
  6553. G:=TSQLGroupGrantee(CheckClass(T.Grantees[0],TSQLGroupGrantee));
  6554. AssertEquals('Grantee B','B',G.Name);
  6555. AssertEquals('One permission',1,T.Privileges.Count);
  6556. CheckClass(T.Privileges[0],TSQLSelectPrivilege);
  6557. AssertEquals('No grant option',False,T.GrantOption);
  6558. end;
  6559. procedure TTestGrantParser.TestProcedurePrivilege;
  6560. Var
  6561. t : TSQLTableGrantStatement;
  6562. G : TSQLProcedureGrantee;
  6563. begin
  6564. TestGrant('GRANT SELECT ON A TO PROCEDURE B');
  6565. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6566. AssertIdentifierName('Table name','A',T.TableName);
  6567. AssertEquals('One grantee', 1,T.Grantees.Count);
  6568. G:=TSQLProcedureGrantee(CheckClass(T.Grantees[0],TSQLProcedureGrantee));
  6569. AssertEquals('Grantee B','B',G.Name);
  6570. AssertEquals('One permission',1,T.Privileges.Count);
  6571. CheckClass(T.Privileges[0],TSQLSelectPrivilege);
  6572. AssertEquals('No grant option',False,T.GrantOption);
  6573. end;
  6574. procedure TTestGrantParser.TestViewPrivilege;
  6575. Var
  6576. t : TSQLTableGrantStatement;
  6577. G : TSQLViewGrantee;
  6578. begin
  6579. TestGrant('GRANT SELECT ON A TO VIEW B');
  6580. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6581. AssertIdentifierName('Table name','A',T.TableName);
  6582. AssertEquals('One grantee', 1,T.Grantees.Count);
  6583. G:=TSQLViewGrantee(CheckClass(T.Grantees[0],TSQLViewGrantee));
  6584. AssertEquals('Grantee B','B',G.Name);
  6585. AssertEquals('One permission',1,T.Privileges.Count);
  6586. CheckClass(T.Privileges[0],TSQLSelectPrivilege);
  6587. AssertEquals('No grant option',False,T.GrantOption);
  6588. end;
  6589. procedure TTestGrantParser.TestTriggerPrivilege;
  6590. Var
  6591. t : TSQLTableGrantStatement;
  6592. G : TSQLTriggerGrantee;
  6593. begin
  6594. TestGrant('GRANT SELECT ON A TO TRIGGER B');
  6595. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6596. AssertIdentifierName('Table name','A',T.TableName);
  6597. AssertEquals('One grantee', 1,T.Grantees.Count);
  6598. G:=TSQLTriggerGrantee(CheckClass(T.Grantees[0],TSQLTriggerGrantee));
  6599. AssertEquals('Grantee B','B',G.Name);
  6600. AssertEquals('One permission',1,T.Privileges.Count);
  6601. CheckClass(T.Privileges[0],TSQLSelectPrivilege);
  6602. AssertEquals('No grant option',False,T.GrantOption);
  6603. end;
  6604. procedure TTestGrantParser.TestPublicPrivilege;
  6605. Var
  6606. t : TSQLTableGrantStatement;
  6607. P : TSQLPublicGrantee;
  6608. begin
  6609. TestGrant('GRANT SELECT ON A TO PUBLIC');
  6610. T:=TSQLTableGrantStatement(CheckClass(Statement,TSQLTableGrantStatement));
  6611. AssertIdentifierName('Table name','A',T.TableName);
  6612. AssertEquals('One grantee', 1,T.Grantees.Count);
  6613. (CheckClass(T.Grantees[0],TSQLPublicGrantee));
  6614. AssertEquals('One permission',1,T.Privileges.Count);
  6615. CheckClass(T.Privileges[0],TSQLSelectPrivilege);
  6616. AssertEquals('No grant option',False,T.GrantOption);
  6617. end;
  6618. procedure TTestGrantParser.TestExecuteToUser;
  6619. Var
  6620. P : TSQLProcedureGrantStatement;
  6621. U : TSQLUserGrantee;
  6622. begin
  6623. TestGrant('GRANT EXECUTE ON PROCEDURE A TO B');
  6624. P:=TSQLProcedureGrantStatement(CheckClass(Statement,TSQLProcedureGrantStatement));
  6625. AssertIdentifierName('Procedure name','A',P.ProcedureName);
  6626. AssertEquals('One grantee', 1,P.Grantees.Count);
  6627. U:=TSQLUserGrantee(CheckClass(P.Grantees[0],TSQLUserGrantee));
  6628. AssertEquals('User name','B',U.Name);
  6629. AssertEquals('No grant option',False,P.GrantOption);
  6630. end;
  6631. procedure TTestGrantParser.TestExecuteToProcedure;
  6632. Var
  6633. P : TSQLProcedureGrantStatement;
  6634. U : TSQLProcedureGrantee;
  6635. begin
  6636. TestGrant('GRANT EXECUTE ON PROCEDURE A TO PROCEDURE B');
  6637. P:=TSQLProcedureGrantStatement(CheckClass(Statement,TSQLProcedureGrantStatement));
  6638. AssertIdentifierName('Procedure name','A',P.ProcedureName);
  6639. AssertEquals('One grantee', 1,P.Grantees.Count);
  6640. U:=TSQLProcedureGrantee(CheckClass(P.Grantees[0],TSQLProcedureGrantee));
  6641. AssertEquals('Procedure grantee name','B',U.Name);
  6642. AssertEquals('No grant option',False,P.GrantOption);
  6643. end;
  6644. procedure TTestGrantParser.TestRoleToUser;
  6645. Var
  6646. R : TSQLRoleGrantStatement;
  6647. U : TSQLUserGrantee;
  6648. begin
  6649. TestGrant('GRANT A TO B');
  6650. R:=TSQLRoleGrantStatement(CheckClass(Statement,TSQLRoleGrantStatement));
  6651. AssertEquals('One role', 1,R.Roles.Count);
  6652. AssertIdentifierName('Role name','A',R.Roles[0]);
  6653. AssertEquals('One grantee', 1,R.Grantees.Count);
  6654. U:=TSQLUserGrantee(CheckClass(R.Grantees[0],TSQLUserGrantee));
  6655. AssertEquals('Procedure grantee name','B',U.Name);
  6656. AssertEquals('No admin option',False,R.AdminOption);
  6657. end;
  6658. procedure TTestGrantParser.TestRoleToUserWithAdmin;
  6659. Var
  6660. R : TSQLRoleGrantStatement;
  6661. U : TSQLUserGrantee;
  6662. begin
  6663. TestGrant('GRANT A TO B WITH ADMIN OPTION');
  6664. R:=TSQLRoleGrantStatement(CheckClass(Statement,TSQLRoleGrantStatement));
  6665. AssertEquals('One role', 1,R.Roles.Count);
  6666. AssertIdentifierName('Role name','A',R.Roles[0]);
  6667. AssertEquals('One grantee', 1,R.Grantees.Count);
  6668. U:=TSQLUserGrantee(CheckClass(R.Grantees[0],TSQLUserGrantee));
  6669. AssertEquals('Procedure grantee name','B',U.Name);
  6670. AssertEquals('Admin option',True,R.AdminOption);
  6671. end;
  6672. procedure TTestGrantParser.TestRoleToPublic;
  6673. Var
  6674. R : TSQLRoleGrantStatement;
  6675. begin
  6676. TestGrant('GRANT A TO PUBLIC');
  6677. R:=TSQLRoleGrantStatement(CheckClass(Statement,TSQLRoleGrantStatement));
  6678. AssertEquals('One role', 1,R.Roles.Count);
  6679. AssertIdentifierName('Role name','A',R.Roles[0]);
  6680. AssertEquals('One grantee', 1,R.Grantees.Count);
  6681. CheckClass(R.Grantees[0],TSQLPublicGrantee);
  6682. AssertEquals('No admin option',False,R.AdminOption);
  6683. end;
  6684. procedure TTestGrantParser.Test2RolesToUser;
  6685. Var
  6686. R : TSQLRoleGrantStatement;
  6687. U : TSQLUserGrantee;
  6688. begin
  6689. TestGrant('GRANT A,C TO B');
  6690. R:=TSQLRoleGrantStatement(CheckClass(Statement,TSQLRoleGrantStatement));
  6691. AssertEquals('2 roles', 2,R.Roles.Count);
  6692. AssertIdentifierName('Role name','A',R.Roles[0]);
  6693. AssertIdentifierName('Role name','C',R.Roles[1]);
  6694. AssertEquals('One grantee', 1,R.Grantees.Count);
  6695. U:=TSQLUserGrantee(CheckClass(R.Grantees[0],TSQLUserGrantee));
  6696. AssertEquals('Procedure grantee name','B',U.Name);
  6697. AssertEquals('No admin option',False,R.AdminOption);
  6698. end;
  6699. { TTestRevokeParser }
  6700. function TTestRevokeParser.TestRevoke(const ASource: String): TSQLRevokeStatement;
  6701. begin
  6702. CreateParser(ASource);
  6703. FToFree:=Parser.Parse;
  6704. If not (FToFree is TSQLRevokeStatement) then
  6705. Fail(Format('Wrong parse result class. Expected TSQLRevokeStatement, got %s',[FTofree.ClassName]));
  6706. Result:=TSQLRevokeStatement(Ftofree);
  6707. FSTatement:=Result;
  6708. AssertEquals('End of stream reached',tsqlEOF,Parser.CurrentToken);
  6709. end;
  6710. procedure TTestRevokeParser.TestRevokeError(const ASource: String);
  6711. begin
  6712. FErrSource:=ASource;
  6713. AssertException(ESQLParser,@TestParseError);
  6714. end;
  6715. procedure TTestRevokeParser.TestSimple;
  6716. Var
  6717. t : TSQLTableRevokeStatement;
  6718. G : TSQLUSerGrantee;
  6719. begin
  6720. TestRevoke('Revoke SELECT ON A FROM B');
  6721. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  6722. AssertIdentifierName('Table name','A',T.TableName);
  6723. AssertEquals('One Grantee', 1,T.Grantees.Count);
  6724. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6725. AssertEquals('Grantee B','B',G.Name);
  6726. AssertEquals('One permission',1,T.Privileges.Count);
  6727. CheckClass(T.Privileges[0],TSQLSelectPrivilege);
  6728. AssertEquals('No Revoke option',False,T.GrantOption);
  6729. end;
  6730. procedure TTestRevokeParser.Test2Operations;
  6731. Var
  6732. t : TSQLTableRevokeStatement;
  6733. G : TSQLUSerGrantee;
  6734. begin
  6735. TestRevoke('Revoke SELECT,INSERT ON A FROM B');
  6736. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  6737. AssertIdentifierName('Table name','A',T.TableName);
  6738. AssertEquals('One Grantee', 1,T.Grantees.Count);
  6739. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6740. AssertEquals('Grantee B','B',G.Name);
  6741. AssertEquals('Two permissions',2,T.Privileges.Count);
  6742. CheckClass(T.Privileges[0],TSQLSelectPrivilege);
  6743. CheckClass(T.Privileges[1],TSQLINSERTPrivilege);
  6744. AssertEquals('No Revoke option',False,T.GrantOption);
  6745. end;
  6746. procedure TTestRevokeParser.TestDeletePrivilege;
  6747. Var
  6748. t : TSQLTableRevokeStatement;
  6749. G : TSQLUSerGrantee;
  6750. begin
  6751. TestRevoke('Revoke DELETE ON A FROM B');
  6752. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  6753. AssertIdentifierName('Table name','A',T.TableName);
  6754. AssertEquals('One Grantee', 1,T.Grantees.Count);
  6755. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6756. AssertEquals('Grantee B','B',G.Name);
  6757. AssertEquals('One permission',1,T.Privileges.Count);
  6758. CheckClass(T.Privileges[0],TSQLDeletePrivilege);
  6759. AssertEquals('No Revoke option',False,T.GrantOption);
  6760. end;
  6761. procedure TTestRevokeParser.TestUpdatePrivilege;
  6762. Var
  6763. t : TSQLTableRevokeStatement;
  6764. G : TSQLUSerGrantee;
  6765. begin
  6766. TestRevoke('Revoke UPDATE ON A FROM B');
  6767. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  6768. AssertIdentifierName('Table name','A',T.TableName);
  6769. AssertEquals('One Grantee', 1,T.Grantees.Count);
  6770. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6771. AssertEquals('Grantee B','B',G.Name);
  6772. AssertEquals('One permission',1,T.Privileges.Count);
  6773. CheckClass(T.Privileges[0],TSQLUPDATEPrivilege);
  6774. AssertEquals('No Revoke option',False,T.GrantOption);
  6775. end;
  6776. procedure TTestRevokeParser.TestInsertPrivilege;
  6777. Var
  6778. t : TSQLTableRevokeStatement;
  6779. G : TSQLUSerGrantee;
  6780. begin
  6781. TestRevoke('Revoke INSERT ON A FROM B');
  6782. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  6783. AssertIdentifierName('Table name','A',T.TableName);
  6784. AssertEquals('One Grantee', 1,T.Grantees.Count);
  6785. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6786. AssertEquals('Grantee B','B',G.Name);
  6787. AssertEquals('One permission',1,T.Privileges.Count);
  6788. CheckClass(T.Privileges[0],TSQLInsertPrivilege);
  6789. AssertEquals('No Revoke option',False,T.GrantOption);
  6790. end;
  6791. procedure TTestRevokeParser.TestReferencePrivilege;
  6792. Var
  6793. t : TSQLTableRevokeStatement;
  6794. G : TSQLUSerGrantee;
  6795. begin
  6796. TestRevoke('Revoke REFERENCES ON A FROM B');
  6797. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  6798. AssertIdentifierName('Table name','A',T.TableName);
  6799. AssertEquals('One Grantee', 1,T.Grantees.Count);
  6800. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6801. AssertEquals('Grantee B','B',G.Name);
  6802. AssertEquals('One permission',1,T.Privileges.Count);
  6803. CheckClass(T.Privileges[0],TSQLReferencePrivilege);
  6804. AssertEquals('No Revoke option',False,T.GrantOption);
  6805. end;
  6806. procedure TTestRevokeParser.TestAllPrivileges;
  6807. Var
  6808. t : TSQLTableRevokeStatement;
  6809. G : TSQLUSerGrantee;
  6810. begin
  6811. TestRevoke('Revoke ALL ON A FROM B');
  6812. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  6813. AssertIdentifierName('Table name','A',T.TableName);
  6814. AssertEquals('One Grantee', 1,T.Grantees.Count);
  6815. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6816. AssertEquals('Grantee B','B',G.Name);
  6817. AssertEquals('One permission',1,T.Privileges.Count);
  6818. CheckClass(T.Privileges[0],TSQLAllPrivilege);
  6819. AssertEquals('No Revoke option',False,T.GrantOption);
  6820. end;
  6821. procedure TTestRevokeParser.TestAllPrivileges2;
  6822. Var
  6823. t : TSQLTableRevokeStatement;
  6824. G : TSQLUSerGrantee;
  6825. begin
  6826. TestRevoke('Revoke ALL PRIVILEGES ON A FROM B');
  6827. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  6828. AssertIdentifierName('Table name','A',T.TableName);
  6829. AssertEquals('One Grantee', 1,T.Grantees.Count);
  6830. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6831. AssertEquals('Grantee B','B',G.Name);
  6832. AssertEquals('One permission',1,T.Privileges.Count);
  6833. CheckClass(T.Privileges[0],TSQLAllPrivilege);
  6834. AssertEquals('No Revoke option',False,T.GrantOption);
  6835. end;
  6836. procedure TTestRevokeParser.TestUpdateColPrivilege;
  6837. Var
  6838. t : TSQLTableRevokeStatement;
  6839. G : TSQLUSerGrantee;
  6840. U : TSQLUPDATEPrivilege;
  6841. begin
  6842. TestRevoke('Revoke UPDATE (C) ON A FROM B');
  6843. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  6844. AssertIdentifierName('Table name','A',T.TableName);
  6845. AssertEquals('One Grantee', 1,T.Grantees.Count);
  6846. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6847. AssertEquals('Grantee B','B',G.Name);
  6848. AssertEquals('One permission',1,T.Privileges.Count);
  6849. U:=TSQLUPDATEPrivilege(CheckClass(T.Privileges[0],TSQLUPDATEPrivilege));
  6850. AssertEquals('1 column',1,U.Columns.Count);
  6851. AssertIdentifierName('Column C','C',U.Columns[0]);
  6852. AssertEquals('No Revoke option',False,T.GrantOption);
  6853. end;
  6854. procedure TTestRevokeParser.TestUpdate2ColsPrivilege;
  6855. Var
  6856. t : TSQLTableRevokeStatement;
  6857. G : TSQLUSerGrantee;
  6858. U : TSQLUPDATEPrivilege;
  6859. begin
  6860. TestRevoke('Revoke UPDATE (C,D) ON A FROM B');
  6861. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  6862. AssertIdentifierName('Table name','A',T.TableName);
  6863. AssertEquals('One Grantee', 1,T.Grantees.Count);
  6864. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6865. AssertEquals('Grantee B','B',G.Name);
  6866. AssertEquals('One permission',1,T.Privileges.Count);
  6867. U:=TSQLUPDATEPrivilege(CheckClass(T.Privileges[0],TSQLUPDATEPrivilege));
  6868. AssertEquals('2 column',2,U.Columns.Count);
  6869. AssertIdentifierName('Column C','C',U.Columns[0]);
  6870. AssertIdentifierName('Column D','D',U.Columns[1]);
  6871. AssertEquals('No Revoke option',False,T.GrantOption);
  6872. end;
  6873. procedure TTestRevokeParser.TestReferenceColPrivilege;
  6874. Var
  6875. t : TSQLTableRevokeStatement;
  6876. G : TSQLUSerGrantee;
  6877. U : TSQLReferencePrivilege;
  6878. begin
  6879. TestRevoke('Revoke REFERENCES (C) ON A FROM B');
  6880. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  6881. AssertIdentifierName('Table name','A',T.TableName);
  6882. AssertEquals('One Grantee', 1,T.Grantees.Count);
  6883. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6884. AssertEquals('Grantee B','B',G.Name);
  6885. AssertEquals('One permission',1,T.Privileges.Count);
  6886. U:=TSQLReferencePrivilege(CheckClass(T.Privileges[0],TSQLReferencePrivilege));
  6887. AssertEquals('1 column',1,U.Columns.Count);
  6888. AssertIdentifierName('Column C','C',U.Columns[0]);
  6889. AssertEquals('No Revoke option',False,T.GrantOption);
  6890. end;
  6891. procedure TTestRevokeParser.TestReference2ColsPrivilege;
  6892. Var
  6893. t : TSQLTableRevokeStatement;
  6894. G : TSQLUSerGrantee;
  6895. U : TSQLReferencePrivilege;
  6896. begin
  6897. TestRevoke('Revoke REFERENCES (C,D) ON A FROM B');
  6898. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  6899. AssertIdentifierName('Table name','A',T.TableName);
  6900. AssertEquals('One Grantee', 1,T.Grantees.Count);
  6901. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6902. AssertEquals('Grantee B','B',G.Name);
  6903. AssertEquals('One permission',1,T.Privileges.Count);
  6904. U:=TSQLReferencePrivilege(CheckClass(T.Privileges[0],TSQLReferencePrivilege));
  6905. AssertEquals('2 column',2,U.Columns.Count);
  6906. AssertIdentifierName('Column C','C',U.Columns[0]);
  6907. AssertIdentifierName('Column D','D',U.Columns[1]);
  6908. AssertEquals('No Revoke option',False,T.GrantOption);
  6909. end;
  6910. procedure TTestRevokeParser.TestUserPrivilege;
  6911. Var
  6912. t : TSQLTableRevokeStatement;
  6913. G : TSQLUSerGrantee;
  6914. begin
  6915. TestRevoke('Revoke SELECT ON A FROM USER B');
  6916. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  6917. AssertIdentifierName('Table name','A',T.TableName);
  6918. AssertEquals('One Grantee', 1,T.Grantees.Count);
  6919. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6920. AssertEquals('Grantee B','B',G.Name);
  6921. AssertEquals('One permission',1,T.Privileges.Count);
  6922. CheckClass(T.Privileges[0],TSQLSelectPrivilege);
  6923. AssertEquals('No Revoke option',False,T.GrantOption);
  6924. end;
  6925. procedure TTestRevokeParser.TestUserPrivilegeWithRevoke;
  6926. Var
  6927. t : TSQLTableRevokeStatement;
  6928. G : TSQLUSerGrantee;
  6929. begin
  6930. TestRevoke('Revoke GRANT OPTION FOR SELECT ON A FROM USER B');
  6931. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  6932. AssertIdentifierName('Table name','A',T.TableName);
  6933. AssertEquals('One Grantee', 1,T.Grantees.Count);
  6934. G:=TSQLUSerGrantee(CheckClass(T.Grantees[0],TSQLUSerGrantee));
  6935. AssertEquals('Grantee B','B',G.Name);
  6936. AssertEquals('One permission',1,T.Privileges.Count);
  6937. CheckClass(T.Privileges[0],TSQLSelectPrivilege);
  6938. AssertEquals('With Revoke option',True,T.GrantOption);
  6939. end;
  6940. procedure TTestRevokeParser.TestGroupPrivilege;
  6941. Var
  6942. t : TSQLTableRevokeStatement;
  6943. G : TSQLGroupGrantee;
  6944. begin
  6945. TestRevoke('Revoke SELECT ON A FROM GROUP B');
  6946. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  6947. AssertIdentifierName('Table name','A',T.TableName);
  6948. AssertEquals('One Grantee', 1,T.Grantees.Count);
  6949. G:=TSQLGroupGrantee(CheckClass(T.Grantees[0],TSQLGroupGrantee));
  6950. AssertEquals('Grantee B','B',G.Name);
  6951. AssertEquals('One permission',1,T.Privileges.Count);
  6952. CheckClass(T.Privileges[0],TSQLSelectPrivilege);
  6953. AssertEquals('No Revoke option',False,T.GrantOption);
  6954. end;
  6955. procedure TTestRevokeParser.TestProcedurePrivilege;
  6956. Var
  6957. t : TSQLTableRevokeStatement;
  6958. G : TSQLProcedureGrantee;
  6959. begin
  6960. TestRevoke('Revoke SELECT ON A FROM PROCEDURE B');
  6961. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  6962. AssertIdentifierName('Table name','A',T.TableName);
  6963. AssertEquals('One Grantee', 1,T.Grantees.Count);
  6964. G:=TSQLProcedureGrantee(CheckClass(T.Grantees[0],TSQLProcedureGrantee));
  6965. AssertEquals('Grantee B','B',G.Name);
  6966. AssertEquals('One permission',1,T.Privileges.Count);
  6967. CheckClass(T.Privileges[0],TSQLSelectPrivilege);
  6968. AssertEquals('No Revoke option',False,T.GrantOption);
  6969. end;
  6970. procedure TTestRevokeParser.TestViewPrivilege;
  6971. Var
  6972. t : TSQLTableRevokeStatement;
  6973. G : TSQLViewGrantee;
  6974. begin
  6975. TestRevoke('Revoke SELECT ON A FROM VIEW B');
  6976. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  6977. AssertIdentifierName('Table name','A',T.TableName);
  6978. AssertEquals('One Grantee', 1,T.Grantees.Count);
  6979. G:=TSQLViewGrantee(CheckClass(T.Grantees[0],TSQLViewGrantee));
  6980. AssertEquals('Grantee B','B',G.Name);
  6981. AssertEquals('One permission',1,T.Privileges.Count);
  6982. CheckClass(T.Privileges[0],TSQLSelectPrivilege);
  6983. AssertEquals('No Revoke option',False,T.GrantOption);
  6984. end;
  6985. procedure TTestRevokeParser.TestTriggerPrivilege;
  6986. Var
  6987. t : TSQLTableRevokeStatement;
  6988. G : TSQLTriggerGrantee;
  6989. begin
  6990. TestRevoke('Revoke SELECT ON A FROM TRIGGER B');
  6991. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  6992. AssertIdentifierName('Table name','A',T.TableName);
  6993. AssertEquals('One Grantee', 1,T.Grantees.Count);
  6994. G:=TSQLTriggerGrantee(CheckClass(T.Grantees[0],TSQLTriggerGrantee));
  6995. AssertEquals('Grantee B','B',G.Name);
  6996. AssertEquals('One permission',1,T.Privileges.Count);
  6997. CheckClass(T.Privileges[0],TSQLSelectPrivilege);
  6998. AssertEquals('No Revoke option',False,T.GrantOption);
  6999. end;
  7000. procedure TTestRevokeParser.TestPublicPrivilege;
  7001. Var
  7002. t : TSQLTableRevokeStatement;
  7003. P : TSQLPublicGrantee;
  7004. begin
  7005. TestRevoke('Revoke SELECT ON A FROM PUBLIC');
  7006. T:=TSQLTableRevokeStatement(CheckClass(Statement,TSQLTableRevokeStatement));
  7007. AssertIdentifierName('Table name','A',T.TableName);
  7008. AssertEquals('One Grantee', 1,T.Grantees.Count);
  7009. (CheckClass(T.Grantees[0],TSQLPublicGrantee));
  7010. AssertEquals('One permission',1,T.Privileges.Count);
  7011. CheckClass(T.Privileges[0],TSQLSelectPrivilege);
  7012. AssertEquals('No Revoke option',False,T.GrantOption);
  7013. end;
  7014. procedure TTestRevokeParser.TestExecuteToUser;
  7015. Var
  7016. P : TSQLProcedureRevokeStatement;
  7017. U : TSQLUserGrantee;
  7018. begin
  7019. TestRevoke('Revoke EXECUTE ON PROCEDURE A FROM B');
  7020. P:=TSQLProcedureRevokeStatement(CheckClass(Statement,TSQLProcedureRevokeStatement));
  7021. AssertIdentifierName('Procedure name','A',P.ProcedureName);
  7022. AssertEquals('One Grantee', 1,P.Grantees.Count);
  7023. U:=TSQLUserGrantee(CheckClass(P.Grantees[0],TSQLUserGrantee));
  7024. AssertEquals('User name','B',U.Name);
  7025. AssertEquals('No Revoke option',False,P.GrantOption);
  7026. end;
  7027. procedure TTestRevokeParser.TestExecuteToProcedure;
  7028. Var
  7029. P : TSQLProcedureRevokeStatement;
  7030. U : TSQLProcedureGrantee;
  7031. begin
  7032. TestRevoke('Revoke EXECUTE ON PROCEDURE A FROM PROCEDURE B');
  7033. P:=TSQLProcedureRevokeStatement(CheckClass(Statement,TSQLProcedureRevokeStatement));
  7034. AssertIdentifierName('Procedure name','A',P.ProcedureName);
  7035. AssertEquals('One Grantee', 1,P.Grantees.Count);
  7036. U:=TSQLProcedureGrantee(CheckClass(P.Grantees[0],TSQLProcedureGrantee));
  7037. AssertEquals('Procedure Grantee name','B',U.Name);
  7038. AssertEquals('No Revoke option',False,P.GrantOption);
  7039. end;
  7040. procedure TTestRevokeParser.TestRoleToUser;
  7041. Var
  7042. R : TSQLRoleRevokeStatement;
  7043. U : TSQLUserGrantee;
  7044. begin
  7045. TestRevoke('Revoke A FROM B');
  7046. R:=TSQLRoleRevokeStatement(CheckClass(Statement,TSQLRoleRevokeStatement));
  7047. AssertEquals('One role', 1,R.Roles.Count);
  7048. AssertIdentifierName('Role name','A',R.Roles[0]);
  7049. AssertEquals('One Grantee', 1,R.Grantees.Count);
  7050. U:=TSQLUserGrantee(CheckClass(R.Grantees[0],TSQLUserGrantee));
  7051. AssertEquals('Procedure Grantee name','B',U.Name);
  7052. AssertEquals('No admin option',False,R.AdminOption);
  7053. end;
  7054. procedure TTestRevokeParser.TestRoleToPublic;
  7055. Var
  7056. R : TSQLRoleRevokeStatement;
  7057. begin
  7058. TestRevoke('Revoke A FROM PUBLIC');
  7059. R:=TSQLRoleRevokeStatement(CheckClass(Statement,TSQLRoleRevokeStatement));
  7060. AssertEquals('One role', 1,R.Roles.Count);
  7061. AssertIdentifierName('Role name','A',R.Roles[0]);
  7062. AssertEquals('One Grantee', 1,R.Grantees.Count);
  7063. CheckClass(R.Grantees[0],TSQLPublicGrantee);
  7064. AssertEquals('No admin option',False,R.AdminOption);
  7065. end;
  7066. procedure TTestRevokeParser.Test2RolesToUser;
  7067. Var
  7068. R : TSQLRoleRevokeStatement;
  7069. U : TSQLUserGrantee;
  7070. begin
  7071. TestRevoke('Revoke A,C FROM B');
  7072. R:=TSQLRoleRevokeStatement(CheckClass(Statement,TSQLRoleRevokeStatement));
  7073. AssertEquals('2 roles', 2,R.Roles.Count);
  7074. AssertIdentifierName('Role name','A',R.Roles[0]);
  7075. AssertIdentifierName('Role name','C',R.Roles[1]);
  7076. AssertEquals('One Grantee', 1,R.Grantees.Count);
  7077. U:=TSQLUserGrantee(CheckClass(R.Grantees[0],TSQLUserGrantee));
  7078. AssertEquals('Procedure Grantee name','B',U.Name);
  7079. AssertEquals('No admin option',False,R.AdminOption);
  7080. end;
  7081. initialization
  7082. RegisterTests([TTestDropParser,
  7083. TTestGeneratorParser,
  7084. TTestRoleParser,
  7085. TTestTypeParser,
  7086. TTestCheckParser,
  7087. TTestDomainParser,
  7088. TTestExceptionParser,
  7089. TTestIndexParser,
  7090. TTestTableParser,
  7091. TTestDeleteParser,
  7092. TTestUpdateParser,
  7093. TTestInsertParser,
  7094. TTestSelectParser,
  7095. TTestRollbackParser,
  7096. TTestCommitParser,
  7097. TTestExecuteProcedureParser,
  7098. TTestConnectParser,
  7099. TTestCreateDatabaseParser,
  7100. TTestAlterDatabaseParser,
  7101. TTestCreateViewParser,
  7102. TTestCreateShadowParser,
  7103. TTestProcedureStatement,
  7104. TTestCreateProcedureParser,
  7105. TTestCreateTriggerParser,
  7106. TTestDeclareExternalFunctionParser,
  7107. TTestGrantParser,
  7108. TTestRevokeParser,
  7109. TTestSetParser,
  7110. TTestGlobalParser]);
  7111. end.