testdbbasics.pas 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657
  1. unit TestDBBasics;
  2. {$IFDEF FPC}
  3. {$mode Delphi}{$H+}
  4. {$ENDIF}
  5. interface
  6. uses
  7. {$IFDEF FPC}
  8. fpcunit, testutils, testregistry, testdecorator,
  9. {$ELSE FPC}
  10. TestFramework,
  11. {$ENDIF FPC}
  12. Classes, SysUtils, db, ToolsUnit;
  13. type
  14. { TTestDBBasics }
  15. TTestDBBasics = class(TTestCase)
  16. private
  17. procedure TestfieldDefinition(AFieldType : TFieldType;ADatasize : integer;var ADS : TDataset; var AFld: TField);
  18. procedure TestcalculatedField_OnCalcfields(DataSet: TDataSet);
  19. protected
  20. procedure SetUp; override;
  21. procedure TearDown; override;
  22. published
  23. procedure TestSetFieldValues;
  24. procedure TestGetFieldValues;
  25. procedure TestSupportIntegerFields;
  26. procedure TestSupportSmallIntFields;
  27. procedure TestSupportStringFields;
  28. procedure TestSupportBooleanFields;
  29. procedure TestSupportFloatFields;
  30. procedure TestSupportLargeIntFields;
  31. procedure TestSupportDateFields;
  32. procedure TestSupportTimeFields;
  33. procedure TestSupportCurrencyFields;
  34. procedure TestSupportBCDFields;
  35. procedure TestSupportfmtBCDFields;
  36. procedure TestSupportFixedStringFields;
  37. procedure TestSupportBlobFields;
  38. procedure TestSupportMemoFields;
  39. procedure TestDoubleClose;
  40. procedure TestCalculatedField;
  41. procedure TestAssignFieldftString;
  42. procedure TestAssignFieldftFixedChar;
  43. procedure TestSelectQueryBasics;
  44. procedure TestPostOnlyInEditState;
  45. procedure TestMove; // bug 5048
  46. procedure TestActiveBufferWhenClosed;
  47. procedure TestEOFBOFClosedDataset;
  48. procedure TestLayoutChangedEvents;
  49. procedure TestDataEventsResync;
  50. procedure TestRecordcountAfterReopen; // partly bug 8228
  51. procedure TestdeFieldListChange;
  52. procedure TestExceptionLocateClosed; // bug 13938
  53. procedure TestCanModifySpecialFields;
  54. procedure TestDetectionNonMatchingDataset;
  55. end;
  56. { TTestBufDatasetDBBasics }
  57. {$ifdef fpc}
  58. TTestBufDatasetDBBasics = class(TTestCase)
  59. private
  60. procedure FTestXMLDatasetDefinition(ADataset : TDataset);
  61. procedure TestAddIndexFieldType(AFieldType : TFieldType; ActiveDS : boolean);
  62. protected
  63. procedure SetUp; override;
  64. procedure TearDown; override;
  65. published
  66. procedure TestClosedIndexFieldNames; // bug 16695
  67. procedure TestFileNameProperty;
  68. procedure TestClientDatasetAsMemDataset;
  69. procedure TestSaveAsXML;
  70. procedure TestIsEmpty;
  71. procedure TestBufDatasetCancelUpd; //bug 6938
  72. procedure TestBufDatasetCancelUpd1;
  73. procedure TestMultipleDeleteUpdateBuffer;
  74. procedure TestDoubleDelete;
  75. procedure TestReadOnly;
  76. procedure TestMergeChangeLog;
  77. // index tests
  78. procedure TestAddIndexInteger;
  79. procedure TestAddIndexSmallInt;
  80. procedure TestAddIndexBoolean;
  81. procedure TestAddIndexFloat;
  82. procedure TestAddIndexLargeInt;
  83. procedure TestAddIndexDateTime;
  84. procedure TestAddIndexCurrency;
  85. procedure TestAddIndexBCD;
  86. procedure TestAddIndex;
  87. procedure TestAddDescIndex;
  88. procedure TestAddCaseInsIndex;
  89. procedure TestInactSwitchIndex;
  90. procedure TestAddIndexActiveDS;
  91. procedure TestAddIndexEditDS;
  92. procedure TestIndexFieldNames;
  93. procedure TestIndexFieldNamesAct;
  94. procedure TestIndexCurRecord;
  95. procedure TestAddDblIndex;
  96. procedure TestIndexEditRecord;
  97. procedure TestIndexAppendRecord;
  98. end;
  99. {$endif fpc}
  100. TTestUniDirectionalDBBasics = class(TTestDBBasics)
  101. end;
  102. { TTestCursorDBBasics }
  103. TTestCursorDBBasics = class(TTestCase)
  104. private
  105. procedure TestOnFilterProc(DataSet: TDataSet; var Accept: Boolean);
  106. procedure FTestDelete1(TestCancelUpdate : boolean);
  107. procedure FTestDelete2(TestCancelUpdate : boolean);
  108. protected
  109. procedure SetUp; override;
  110. procedure TearDown; override;
  111. published
  112. procedure TestCancelUpdDelete1;
  113. procedure TestCancelUpdDelete2;
  114. procedure TestAppendInsertRecord;
  115. procedure TestBookmarks;
  116. procedure TestBookmarkValid;
  117. procedure TestDelete1;
  118. procedure TestDelete2;
  119. procedure TestLocate;
  120. procedure TestLocateCaseIns;
  121. procedure TestFirst;
  122. procedure TestIntFilter;
  123. procedure TestOnFilter;
  124. procedure TestStringFilter;
  125. procedure TestNullAtOpen;
  126. procedure TestAppendOnEmptyDataset;
  127. procedure TestInsertOnEmptyDataset;
  128. procedure TestEofAfterFirst; //bug 7211
  129. procedure TestLastAppendCancel; // bug 5058
  130. procedure TestRecNo; // bug 5061
  131. procedure TestSetRecNo; // bug 6919
  132. procedure TestBug7007;
  133. procedure TestBug6893;
  134. procedure TestRequired;
  135. procedure TestOldValueObsolete;
  136. procedure TestOldValue;
  137. procedure TestModified;
  138. end;
  139. { TDBBasicsUniDirectionalTestSetup }
  140. {$ifdef fpc}
  141. TDBBasicsUniDirectionalTestSetup = class(TDBBasicsTestSetup)
  142. protected
  143. procedure OneTimeSetup; override;
  144. procedure OneTimeTearDown; override;
  145. end;
  146. {$endif fpc}
  147. implementation
  148. uses
  149. {$ifdef fpc}
  150. bufdataset,
  151. sqldb,
  152. {$endif fpc}
  153. variants,
  154. strutils,
  155. FmtBCD;
  156. type THackDataLink=class(TdataLink);
  157. { TTestCursorDBBasics }
  158. procedure TTestCursorDBBasics.SetUp;
  159. begin
  160. DBConnector.StartTest;
  161. end;
  162. procedure TTestCursorDBBasics.TearDown;
  163. begin
  164. DBConnector.StopTest;
  165. end;
  166. procedure TTestCursorDBBasics.TestAppendOnEmptyDataset;
  167. begin
  168. with DBConnector.GetNDataset(0) do
  169. begin
  170. open;
  171. CheckTrue(CanModify);
  172. CheckTrue(eof);
  173. CheckTrue(bof);
  174. append;
  175. FieldByName('id').AsInteger:=0;
  176. CheckFalse(Bof);
  177. CheckTrue(Eof);
  178. post;
  179. CheckFalse(eof);
  180. CheckFalse(bof);
  181. end;
  182. end;
  183. procedure TTestCursorDBBasics.TestInsertOnEmptyDataset;
  184. begin
  185. with DBConnector.GetNDataset(0) do
  186. begin
  187. open;
  188. CheckTrue(CanModify);
  189. CheckTrue(eof);
  190. CheckTrue(bof);
  191. CheckTrue(IsEmpty);
  192. insert;
  193. FieldByName('id').AsInteger:=0;
  194. CheckTrue(Bof);
  195. CheckTrue(Eof);
  196. CheckFalse(IsEmpty);
  197. post;
  198. CheckFalse(IsEmpty);
  199. CheckFalse(eof);
  200. CheckFalse(bof);
  201. end;
  202. end;
  203. procedure TTestDBBasics.TestSelectQueryBasics;
  204. var b : TFieldType;
  205. begin
  206. with DBConnector.GetNDataset(1) do
  207. begin
  208. Open;
  209. if IsUniDirectional then
  210. CheckEquals(-1,RecNo)
  211. else
  212. CheckEquals(1,RecNo);
  213. CheckEquals(1,RecordCount);
  214. CheckEquals(2,FieldCount);
  215. CheckTrue(CompareText('ID',fields[0].FieldName)=0);
  216. CheckTrue(CompareText('ID',fields[0].DisplayName)=0);
  217. CheckTrue(ftInteger=fields[0].DataType, 'The datatype of the field ''ID'' is incorrect, it should be ftInteger');
  218. CheckTrue(CompareText('NAME',fields[1].FieldName)=0);
  219. CheckTrue(CompareText('NAME',fields[1].DisplayName)=0);
  220. CheckTrue(ftString=fields[1].DataType);
  221. CheckEquals(1,fields[0].Value);
  222. CheckEquals('TestName1',fields[1].Value);
  223. Close;
  224. end;
  225. end;
  226. procedure TTestDBBasics.TestPostOnlyInEditState;
  227. begin
  228. with DBConnector.GetNDataset(1) do
  229. begin
  230. open;
  231. CheckException(Post,EDatabaseError,'Post was called in a non-edit state');
  232. end;
  233. end;
  234. procedure TTestDBBasics.TestMove;
  235. var i,count : integer;
  236. aDatasource : TDataSource;
  237. aDatalink : TDataLink;
  238. ABufferCount : Integer;
  239. begin
  240. aDatasource := TDataSource.Create(nil);
  241. aDatalink := TTestDataLink.Create;
  242. try
  243. aDatalink.DataSource := aDatasource;
  244. ABufferCount := 11;
  245. aDatalink.BufferCount := ABufferCount;
  246. DataEvents := '';
  247. for count := 0 to 32 do
  248. begin
  249. aDatasource.DataSet := DBConnector.GetNDataset(count);
  250. with aDatasource.Dataset do
  251. begin
  252. i := 1;
  253. Open;
  254. CheckEquals('deUpdateState:0;',DataEvents);
  255. DataEvents := '';
  256. while not EOF do
  257. begin
  258. CheckEquals(i,fields[0].AsInteger);
  259. CheckEquals('TestName'+inttostr(i),fields[1].AsString);
  260. inc(i);
  261. Next;
  262. if (i > ABufferCount) and not EOF then
  263. CheckEquals('deCheckBrowseMode:0;deDataSetScroll:-1;DataSetScrolled:1;DataSetChanged;',DataEvents)
  264. else
  265. CheckEquals('deCheckBrowseMode:0;deDataSetScroll:0;DataSetScrolled:0;DataSetChanged;',DataEvents);
  266. DataEvents := '';
  267. end;
  268. CheckEquals(count,i-1);
  269. close;
  270. CheckEquals('deUpdateState:0;',DataEvents);
  271. DataEvents := '';
  272. end;
  273. end;
  274. finally
  275. aDatalink.Free;
  276. aDatasource.Free;
  277. end;
  278. end;
  279. procedure TTestDBBasics.TestdeFieldListChange;
  280. var i,count : integer;
  281. aDatasource : TDataSource;
  282. aDatalink : TDataLink;
  283. ds : TDataset;
  284. begin
  285. aDatasource := TDataSource.Create(nil);
  286. aDatalink := TTestDataLink.Create;
  287. aDatalink.DataSource := aDatasource;
  288. ds := DBConnector.GetNDataset(1);
  289. with ds do
  290. begin
  291. aDatasource.DataSet := ds;
  292. DataEvents := '';
  293. open;
  294. Fields.add(tfield.Create(DBConnector.GetNDataset(1)));
  295. CheckEquals('deUpdateState:0;deFieldListChange:0;',DataEvents);
  296. DataEvents := '';
  297. fields.Clear;
  298. CheckEquals('deFieldListChange:0;',DataEvents)
  299. end;
  300. aDatasource.Free;
  301. aDatalink.Free;
  302. end;
  303. procedure TTestDBBasics.TestActiveBufferWhenClosed;
  304. begin
  305. with DBConnector.GetNDataset(0) do
  306. begin
  307. {$ifdef fpc}
  308. AssertNull(ActiveBuffer);
  309. {$endif fpc}
  310. open;
  311. CheckFalse(ActiveBuffer = nil,'Activebuffer of an empty dataset shouldn''t be nil');
  312. end;
  313. end;
  314. procedure TTestDBBasics.TestEOFBOFClosedDataset;
  315. begin
  316. with DBConnector.GetNDataset(1) do
  317. begin
  318. CheckTrue(EOF);
  319. CheckTrue(BOF);
  320. open;
  321. CheckTrue(BOF, 'No BOF when opened non-empty dataset');
  322. CheckFalse(EOF, 'EOF after opened non-empty dataset');
  323. close;
  324. CheckTrue(EOF);
  325. CheckTrue(BOF);
  326. end;
  327. end;
  328. procedure TTestDBBasics.TestLayoutChangedEvents;
  329. var aDatasource : TDataSource;
  330. aDatalink : TDataLink;
  331. ds : tdataset;
  332. begin
  333. aDatasource := TDataSource.Create(nil);
  334. aDatalink := TTestDataLink.Create;
  335. try
  336. aDatalink.DataSource := aDatasource;
  337. ds := DBConnector.GetNDataset(6);
  338. aDatasource.DataSet:=ds;
  339. with ds do
  340. begin
  341. open;
  342. DataEvents := '';
  343. DisableControls;
  344. Active:=False;
  345. Active:=True;
  346. EnableControls;
  347. CheckEquals('deLayoutChange:0;DataSetChanged;',DataEvents);
  348. close;
  349. end;
  350. finally
  351. aDatasource.Free;
  352. aDatalink.Free;
  353. end;
  354. end;
  355. procedure TTestDBBasics.TestDataEventsResync;
  356. var i,count : integer;
  357. aDatasource : TDataSource;
  358. aDatalink : TDataLink;
  359. ds : tdataset;
  360. begin
  361. aDatasource := TDataSource.Create(nil);
  362. aDatalink := TTestDataLink.Create;
  363. try
  364. aDatalink.DataSource := aDatasource;
  365. ds := DBConnector.GetNDataset(6);
  366. ds.BeforeScroll := DBConnector.DataEvent;
  367. with ds do
  368. begin
  369. aDatasource.DataSet := ds;
  370. open;
  371. DataEvents := '';
  372. Resync([rmExact]);
  373. CheckEquals('deDataSetChange:0;DataSetChanged;',DataEvents);
  374. DataEvents := '';
  375. next;
  376. CheckEquals('deCheckBrowseMode:0;DataEvent;deDataSetScroll:0;DataSetScrolled:1;DataSetChanged;',DataEvents);
  377. close;
  378. end;
  379. finally
  380. aDatasource.Free;
  381. aDatalink.Free;
  382. end;
  383. end;
  384. procedure TTestCursorDBBasics.TestLastAppendCancel;
  385. var count : integer;
  386. begin
  387. for count := 0 to 32 do with DBConnector.GetNDataset(count) do
  388. begin
  389. open;
  390. Last;
  391. Append;
  392. Cancel;
  393. CheckEquals(count,fields[0].asinteger);
  394. CheckEquals(count,RecordCount);
  395. Close;
  396. end;
  397. end;
  398. procedure TTestCursorDBBasics.TestRecNo;
  399. var i : longint;
  400. passed : boolean;
  401. begin
  402. with DBConnector.GetNDataset(0) do
  403. begin
  404. // Accessing RecNo on a closed dataset should raise an EDatabaseError or should
  405. // return 0
  406. passed := false;
  407. try
  408. i := recno;
  409. except on E: Exception do
  410. begin
  411. passed := E.classname = EDatabaseError.className
  412. end;
  413. end;
  414. if not passed then
  415. CheckEquals(0,RecNo,'Failed to get the RecNo from a closed dataset');
  416. // Accessing Recordcount on a closed dataset should raise an EDatabaseError or should
  417. // return 0
  418. passed := false;
  419. try
  420. i := recordcount;
  421. except on E: Exception do
  422. begin
  423. passed := E.classname = EDatabaseError.className
  424. end;
  425. end;
  426. if not passed then
  427. CheckEquals(0,RecNo,'Failed to get the Recordcount from a closed dataset');
  428. Open;
  429. CheckEquals(0,RecordCount);
  430. CheckEquals(0,RecNo);
  431. first;
  432. CheckEquals(0,RecordCount);
  433. CheckEquals(0,RecNo);
  434. last;
  435. CheckEquals(0,RecordCount);
  436. CheckEquals(0,RecNo);
  437. append;
  438. CheckEquals(0,RecNo);
  439. CheckEquals(0,RecordCount);
  440. first;
  441. CheckEquals(0,RecNo);
  442. CheckEquals(0,RecordCount);
  443. append;
  444. FieldByName('id').AsInteger := 1;
  445. CheckEquals(0,RecNo);
  446. CheckEquals(0,RecordCount);
  447. first;
  448. CheckEquals(1,RecNo);
  449. CheckEquals(1,RecordCount);
  450. last;
  451. CheckEquals(1,RecNo);
  452. CheckEquals(1,RecordCount);
  453. append;
  454. FieldByName('id').AsInteger := 1;
  455. CheckEquals(0,RecNo);
  456. CheckEquals(1,RecordCount);
  457. Close;
  458. end;
  459. end;
  460. procedure TTestCursorDBBasics.TestSetRecNo;
  461. begin
  462. with DBConnector.GetNDataset(15) do
  463. begin
  464. Open;
  465. RecNo := 1;
  466. CheckEquals(1,fields[0].AsInteger);
  467. CheckEquals(1,RecNo);
  468. RecNo := 2;
  469. CheckEquals(2,fields[0].AsInteger);
  470. CheckEquals(2,RecNo);
  471. RecNo := 8;
  472. CheckEquals(8,fields[0].AsInteger);
  473. CheckEquals(8,RecNo);
  474. RecNo := 15;
  475. CheckEquals(15,fields[0].AsInteger);
  476. CheckEquals(15,RecNo);
  477. RecNo := 3;
  478. CheckEquals(3,fields[0].AsInteger);
  479. CheckEquals(3,RecNo);
  480. RecNo := 14;
  481. CheckEquals(14,fields[0].AsInteger);
  482. CheckEquals(14,RecNo);
  483. RecNo := 15;
  484. CheckEquals(15,fields[0].AsInteger);
  485. CheckEquals(15,RecNo);
  486. // test for exceptions...
  487. { RecNo := 16;
  488. CheckEquals(15,fields[0].AsInteger);
  489. CheckEquals(15,RecNo);}
  490. Close;
  491. end;
  492. end;
  493. procedure TTestCursorDBBasics.TestRequired;
  494. begin
  495. with DBConnector.GetNDataset(2) do
  496. begin
  497. Open;
  498. FieldByName('ID').Required := True;
  499. Append;
  500. CheckException(Post, EDatabaseError);
  501. FieldByName('ID').AsInteger := 1000;
  502. Post;
  503. Close;
  504. end;
  505. end;
  506. procedure TTestDBBasics.TestExceptionLocateClosed;
  507. var passed: boolean;
  508. begin
  509. with DBConnector.GetNDataset(15) do
  510. begin
  511. passed := false;
  512. try
  513. locate('name','TestName1',[]);
  514. except on E: Exception do
  515. begin
  516. passed := E.classname = EDatabaseError.className
  517. end;
  518. end;
  519. CheckTrue(passed);
  520. end;
  521. end;
  522. procedure TTestDBBasics.SetUp;
  523. begin
  524. DBConnector.StartTest;
  525. end;
  526. procedure TTestDBBasics.TearDown;
  527. begin
  528. DBConnector.StopTest;
  529. end;
  530. procedure TTestCursorDBBasics.TestOldValueObsolete;
  531. var v : variant;
  532. bufds: TDataset;
  533. begin
  534. // this test was created as reaction to AV bug found in TCustomBufDataset.GetFieldData
  535. // when retrieving OldValue (State=dsOldValue) of newly inserted or appended record.
  536. // In this case was CurrBuff set to nil (and not checked),
  537. // because OldValuesBuffer for just inserted record is nil. See rev.17704
  538. // (So purpose of this test isn't test InsertRecord on empty dataset or so)
  539. // Later was this test replaced by more complex TestOldValue (superset of old test),
  540. // but next to it was restored back also original test.
  541. // So now we have two tests which test same thing, where this 'old' one is subset of 'new' one
  542. // Ideal solution would be remove this 'old' test as it does not test anything what is not tested elsewhere ...
  543. bufds := DBConnector.GetNDataset(0) as TDataset;
  544. bufds.Open;
  545. bufds.InsertRecord([0,'name']);
  546. v := VarToStr(bufds.fields[1].OldValue);
  547. end;
  548. procedure TTestCursorDBBasics.TestOldValue;
  549. begin
  550. with DBConnector.GetNDataset(1) as TDataset do
  551. begin;
  552. Open;
  553. First;
  554. CheckEquals('1', VarToStr(Fields[0].OldValue), 'Original value'); // unmodified original value
  555. CheckTrue(UpdateStatus=usUnmodified, 'Unmodified');
  556. Edit;
  557. Fields[0].AsInteger := -1;
  558. CheckEquals('1', VarToStr(Fields[0].OldValue), 'Editing'); // dsEdit, there is no update-buffer yet
  559. Post;
  560. CheckEquals('1', VarToStr(Fields[0].OldValue), 'Edited'); // there is already update-buffer
  561. CheckTrue(UpdateStatus=usModified, 'Modified');
  562. Append;
  563. Fields[0].AsInteger := -2;
  564. CheckTrue(VarIsNull(Fields[0].OldValue), 'Inserting'); // dsInsert, there is no update-buffer yet
  565. Post;
  566. CheckTrue(VarIsNull(Fields[0].OldValue), 'Inserted'); // there is already update-buffer
  567. CheckTrue(UpdateStatus=usInserted, 'Inserted');
  568. end;
  569. end;
  570. procedure TTestCursorDBBasics.TestModified;
  571. begin
  572. // Tests TDataSet.Modified property
  573. with DBConnector.GetNDataset(true,1) as TDataset do
  574. begin
  575. Open;
  576. CheckFalse(Modified);
  577. Edit;
  578. CheckFalse(Modified, 'After Edit');
  579. Fields[1].AsString := Fields[1].AsString;
  580. CheckTrue(Modified, 'After change');
  581. Post;
  582. CheckFalse(Modified, 'After Post');
  583. Append;
  584. CheckFalse(Modified, 'After Append');
  585. Fields[0].AsInteger := 100;
  586. CheckTrue(Modified, 'After change');
  587. Cancel;
  588. CheckFalse(Modified, 'After Cancel');
  589. Close;
  590. end;
  591. end;
  592. procedure TTestDBBasics.TestCanModifySpecialFields;
  593. var ds : TDataset;
  594. lds : TDataset;
  595. fld : TField;
  596. begin
  597. lds := DBConnector.GetNDataset(10);
  598. ds := DBConnector.GetNDataset(5);
  599. with ds do
  600. begin
  601. Fld := TIntegerField.Create(ds);
  602. Fld.FieldName:='ID';
  603. Fld.DataSet:=ds;
  604. Fld := TStringField.Create(ds);
  605. Fld.FieldName:='LookupFld';
  606. Fld.FieldKind:=fkLookup;
  607. Fld.DataSet:=ds;
  608. Fld.LookupDataSet:=lds;
  609. Fld.LookupResultField:='NAME';
  610. Fld.LookupKeyFields:='ID';
  611. Fld.KeyFields:='ID';
  612. lds.Open;
  613. Open;
  614. CheckTrue(FieldByName('ID').CanModify);
  615. CheckFalse(FieldByName('LookupFld').CanModify);
  616. CheckFalse(FieldByName('ID').ReadOnly);
  617. CheckFalse(FieldByName('LookupFld').ReadOnly);
  618. CheckEquals(1,FieldByName('ID').AsInteger);
  619. CheckEquals('TestName1',FieldByName('LookupFld').AsString);
  620. Next;
  621. Next;
  622. CheckEquals(3,FieldByName('ID').AsInteger);
  623. CheckEquals('TestName3',FieldByName('LookupFld').AsString);
  624. Close;
  625. lds.Close;
  626. end;
  627. end;
  628. procedure TTestDBBasics.TestDetectionNonMatchingDataset;
  629. var
  630. F: TField;
  631. ds: tdataset;
  632. begin
  633. // TDataset.Bindfields should detect problems when the underlying data does
  634. // not reflect the fields of the dataset. This test is to check if this is
  635. // really done.
  636. ds := DBConnector.GetNDataset(true,6);
  637. with ds do
  638. begin
  639. open;
  640. close;
  641. F := TStringField.Create(ds);
  642. F.FieldName:='DOES_NOT_EXIST';
  643. F.DataSet:=ds;
  644. F.Size:=50;
  645. CheckException(open,EDatabaseError);
  646. end;
  647. end;
  648. procedure TTestCursorDBBasics.TestAppendInsertRecord;
  649. begin
  650. with DBConnector.GetNDataset(true,6) do
  651. begin
  652. open;
  653. // InsertRecord should insert a record, set the values, post the record and
  654. // make the new record active.
  655. InsertRecord([152,'TestInsRec']);
  656. CheckEquals(152,fields[0].AsInteger);
  657. CheckEquals('TestInsRec',fields[1].AsString);
  658. CheckTrue(state=dsBrowse);
  659. // AppendRecord should append a record, further the same as InsertRecord
  660. AppendRecord([151,'TestInsRec']);
  661. CheckEquals(151,fields[0].AsInteger);
  662. CheckEquals('TestInsRec',fields[1].AsString);
  663. CheckTrue(state=dsBrowse);
  664. next;
  665. CheckTrue(EOF);
  666. end;
  667. end;
  668. procedure TTestCursorDBBasics.TestBookmarks;
  669. var BM1,BM2,BM3,BM4,BM5 : TBookmark;
  670. begin
  671. with DBConnector.GetNDataset(true,14) do
  672. begin
  673. {$ifdef fpc}
  674. AssertNull(GetBookmark);
  675. {$endif fpc}
  676. open;
  677. BM1:=GetBookmark; // id=1, BOF
  678. next;next;
  679. BM2:=GetBookmark; // id=3
  680. next;next;next;
  681. BM3:=GetBookmark; // id=6
  682. next;next;next;next;next;next;next;next;
  683. BM4:=GetBookmark; // id=14
  684. next;
  685. BM5:=GetBookmark; // id=14, EOF
  686. GotoBookmark(BM2);
  687. CheckEquals(3,FieldByName('id').AsInteger);
  688. GotoBookmark(BM1);
  689. CheckEquals(1,FieldByName('id').AsInteger);
  690. GotoBookmark(BM3);
  691. CheckEquals(6,FieldByName('id').AsInteger);
  692. GotoBookmark(BM4);
  693. CheckEquals(14,FieldByName('id').AsInteger);
  694. GotoBookmark(BM3);
  695. CheckEquals(6,FieldByName('id').AsInteger);
  696. GotoBookmark(BM5);
  697. CheckEquals(14,FieldByName('id').AsInteger);
  698. GotoBookmark(BM1);
  699. CheckEquals(1,FieldByName('id').AsInteger);
  700. next;
  701. delete;
  702. GotoBookmark(BM2);
  703. CheckEquals(3,FieldByName('id').AsInteger);
  704. delete;delete;
  705. GotoBookmark(BM3);
  706. CheckEquals(6,FieldByName('id').AsInteger);
  707. GotoBookmark(BM1);
  708. CheckEquals(1,FieldByName('id').AsInteger);
  709. insert;
  710. fieldbyname('id').AsInteger:=20;
  711. insert;
  712. fieldbyname('id').AsInteger:=21;
  713. insert;
  714. fieldbyname('id').AsInteger:=22;
  715. insert;
  716. fieldbyname('id').AsInteger:=23;
  717. post;
  718. GotoBookmark(BM3);
  719. CheckEquals(6,FieldByName('id').AsInteger);
  720. GotoBookmark(BM1);
  721. CheckEquals(1,FieldByName('id').AsInteger);
  722. GotoBookmark(BM5);
  723. CheckEquals(14,FieldByName('id').AsInteger);
  724. end;
  725. end;
  726. procedure TTestCursorDBBasics.TestBookmarkValid;
  727. var BM1,BM2,BM3,BM4,BM5 : TBookmark;
  728. begin
  729. with DBConnector.GetNDataset(true,14) do
  730. begin
  731. BM1 := Nil;
  732. CheckFalse(BookmarkValid(BM1));
  733. open;
  734. BM1:=GetBookmark; // id=1, BOF
  735. CheckTrue(BookmarkValid(BM1));
  736. next;next;
  737. BM2:=GetBookmark; // id=3
  738. CheckTrue(BookmarkValid(BM2));
  739. next;next;next;
  740. BM3:=GetBookmark; // id=6
  741. CheckTrue(BookmarkValid(BM3));
  742. next;next;next;next;next;next;next;next;
  743. BM4:=GetBookmark; // id=14
  744. CheckTrue(BookmarkValid(BM4));
  745. next;
  746. BM5:=GetBookmark; // id=14, EOF
  747. CheckTrue(BookmarkValid(BM5));
  748. CheckTrue(BookmarkValid(BM4));
  749. CheckTrue(BookmarkValid(BM3));
  750. CheckTrue(BookmarkValid(BM2));
  751. CheckTrue(BookmarkValid(BM1));
  752. GotoBookmark(BM2);
  753. CheckTrue(BookmarkValid(BM5));
  754. CheckTrue(BookmarkValid(BM4));
  755. CheckTrue(BookmarkValid(BM3));
  756. CheckTrue(BookmarkValid(BM2));
  757. CheckTrue(BookmarkValid(BM1));
  758. end;
  759. end;
  760. procedure TTestCursorDBBasics.TestLocate;
  761. begin
  762. with DBConnector.GetNDataset(true,13) do
  763. begin
  764. open;
  765. CheckTrue(Locate('id',vararrayof([5]),[]));
  766. CheckEquals(5,FieldByName('id').AsInteger);
  767. CheckFalse(Locate('id',vararrayof([15]),[]));
  768. CheckTrue(Locate('id',vararrayof([12]),[]));
  769. CheckEquals(12,FieldByName('id').AsInteger);
  770. close;
  771. open;
  772. CheckTrue(Locate('id',vararrayof([12]),[]));
  773. CheckEquals(12,FieldByName('id').AsInteger);
  774. CheckTrue(Locate('id;name',vararrayof([4,'TestName4']),[]));
  775. CheckEquals(4,FieldByName('id').AsInteger);
  776. CheckFalse(Locate('id;name',vararrayof([4,'TestName5']),[]));
  777. end;
  778. end;
  779. procedure TTestCursorDBBasics.TestLocateCaseIns;
  780. begin
  781. with DBConnector.GetNDataset(true,13) do
  782. begin
  783. open;
  784. CheckFalse(Locate('name',vararrayof(['TEstName5']),[]));
  785. CheckTrue(Locate('name',vararrayof(['TEstName5']),[loCaseInsensitive]));
  786. CheckEquals(5,FieldByName('id').AsInteger);
  787. CheckFalse(Locate('name',vararrayof(['TestN']),[]));
  788. CheckTrue(Locate('name',vararrayof(['TestN']),[loPartialKey]));
  789. CheckFalse(Locate('name',vararrayof(['TestNA']),[loPartialKey]));
  790. CheckTrue(Locate('name',vararrayof(['TestNA']),[loPartialKey, loCaseInsensitive]));
  791. close;
  792. end;
  793. end;
  794. procedure TTestDBBasics.TestSetFieldValues;
  795. var PassException : boolean;
  796. begin
  797. with DBConnector.GetNDataset(true,11) do
  798. begin
  799. open;
  800. first;
  801. edit;
  802. FieldValues['id']:=5;
  803. post;
  804. CheckEquals('TestName1',FieldByName('name').AsString);
  805. CheckEquals(5,FieldByName('id').AsInteger);
  806. edit;
  807. FieldValues['name']:='FieldValuesTestName';
  808. post;
  809. CheckEquals('FieldValuesTestName',FieldByName('name').AsString);
  810. CheckEquals(5,FieldByName('id').AsInteger);
  811. edit;
  812. FieldValues['id;name']:= VarArrayOf([243,'ValuesTestName']);
  813. post;
  814. CheckEquals('ValuesTestName',FieldByName('name').AsString);
  815. CheckEquals(243,FieldByName('id').AsInteger);
  816. PassException:=false;
  817. try
  818. edit;
  819. FieldValues['id;name;fake']:= VarArrayOf([243,'ValuesTestName',4]);
  820. except
  821. on E: EDatabaseError do PassException := True;
  822. end;
  823. post;
  824. CheckTrue(PassException);
  825. end;
  826. end;
  827. procedure TTestDBBasics.TestGetFieldValues;
  828. var AVar : Variant;
  829. PassException : boolean;
  830. begin
  831. with DBConnector.GetNDataset(true,14) do
  832. begin
  833. open;
  834. AVar:=FieldValues['id'];
  835. CheckEquals(AVar,1);
  836. AVar:=FieldValues['name'];
  837. CheckEquals(AVar,'TestName1');
  838. AVar:=FieldValues['id;name'];
  839. CheckEquals(AVar[0],1);
  840. CheckEquals(AVar[1],'TestName1');
  841. AVar:=FieldValues['name;id;'];
  842. CheckEquals(AVar[1],1);
  843. CheckEquals(AVar[0],'TestName1');
  844. PassException:=false;
  845. try
  846. AVar:=FieldValues['name;id;fake'];
  847. except
  848. on E: EDatabaseError do PassException := True;
  849. end;
  850. CheckTrue(PassException);
  851. end;
  852. end;
  853. procedure TTestCursorDBBasics.TestFirst;
  854. var i : integer;
  855. begin
  856. with DBConnector.GetNDataset(true,14) do
  857. begin
  858. open;
  859. CheckEquals(1,FieldByName('ID').AsInteger);
  860. First;
  861. CheckEquals(1,FieldByName('ID').AsInteger);
  862. next;
  863. CheckEquals(2,FieldByName('ID').AsInteger);
  864. First;
  865. CheckEquals(1,FieldByName('ID').AsInteger);
  866. for i := 0 to 12 do
  867. next;
  868. CheckEquals(14,FieldByName('ID').AsInteger);
  869. First;
  870. CheckEquals(1,FieldByName('ID').AsInteger);
  871. close;
  872. end;
  873. end;
  874. procedure TTestCursorDBBasics.TestDelete1;
  875. begin
  876. FTestDelete1(false);
  877. end;
  878. procedure TTestCursorDBBasics.TestDelete2;
  879. begin
  880. FTestDelete2(false);
  881. end;
  882. procedure TTestCursorDBBasics.TestCancelUpdDelete1;
  883. begin
  884. FTestDelete1(true);
  885. end;
  886. procedure TTestCursorDBBasics.TestCancelUpdDelete2;
  887. begin
  888. FTestDelete2(true);
  889. end;
  890. procedure TTestCursorDBBasics.FTestDelete1(TestCancelUpdate : boolean);
  891. // Test the deletion of records, including the first and the last one
  892. var i : integer;
  893. ds : TDataset;
  894. begin
  895. ds := DBConnector.GetNDataset(true,17);
  896. with ds do
  897. begin
  898. Open;
  899. for i := 0 to 16 do if i mod 4=0 then
  900. delete
  901. else
  902. next;
  903. First;
  904. for i := 0 to 16 do
  905. begin
  906. if i mod 4<>0 then
  907. begin
  908. CheckEquals(i+1,FieldByName('ID').AsInteger);
  909. CheckEquals('TestName'+inttostr(i+1),FieldByName('NAME').AsString);
  910. next;
  911. end;
  912. end;
  913. end;
  914. {$ifdef fpc}
  915. if TestCancelUpdate then
  916. begin
  917. if not (ds is TCustomBufDataset) then
  918. Ignore('This test only applies to TCustomBufDataset and descendents.');
  919. with TCustomBufDataset(ds) do
  920. begin
  921. CancelUpdates;
  922. First;
  923. for i := 0 to 16 do
  924. begin
  925. CheckEquals(i+1,FieldByName('ID').AsInteger);
  926. CheckEquals('TestName'+inttostr(i+1),FieldByName('NAME').AsString);
  927. next;
  928. end;
  929. close;
  930. end;
  931. end;
  932. {$endif}
  933. end;
  934. procedure TTestCursorDBBasics.FTestDelete2(TestCancelUpdate : boolean);
  935. // Test the deletion of edited and appended records
  936. var i : integer;
  937. ds : TDataset;
  938. begin
  939. ds := DBConnector.GetNDataset(true,17);
  940. with ds do
  941. begin
  942. Open;
  943. for i := 0 to 16 do
  944. begin
  945. if i mod 4=0 then
  946. begin
  947. edit;
  948. fieldbyname('name').AsString:='this record will be gone soon';
  949. post;
  950. end;
  951. next;
  952. end;
  953. for i := 17 to 20 do
  954. begin
  955. append;
  956. fieldbyname('id').AsInteger:=i+1;
  957. fieldbyname('name').AsString:='TestName'+inttostr(i+1);
  958. post;
  959. end;
  960. first;
  961. for i := 0 to 20 do if i mod 4=0 then
  962. delete
  963. else
  964. next;
  965. First;
  966. i := 0;
  967. for i := 0 to 20 do
  968. begin
  969. if i mod 4<>0 then
  970. begin
  971. CheckEquals(i+1,FieldByName('ID').AsInteger);
  972. CheckEquals('TestName'+inttostr(i+1),FieldByName('NAME').AsString);
  973. next;
  974. end;
  975. end;
  976. end;
  977. {$ifdef fpc}
  978. if TestCancelUpdate then
  979. begin
  980. if not (ds is TCustomBufDataset) then
  981. Ignore('This test only applies to TCustomBufDataset and descendents.');
  982. with TCustomBufDataset(ds) do
  983. begin
  984. CancelUpdates;
  985. First;
  986. for i := 0 to 16 do
  987. begin
  988. CheckEquals(i+1,FieldByName('ID').AsInteger);
  989. CheckEquals('TestName'+inttostr(i+1),FieldByName('NAME').AsString);
  990. next;
  991. end;
  992. close;
  993. end;
  994. end;
  995. {$endif fpc}
  996. end;
  997. procedure TTestCursorDBBasics.TestOnFilterProc(DataSet: TDataSet; var Accept: Boolean);
  998. var a : TDataSetState;
  999. begin
  1000. Accept := odd(Dataset.FieldByName('ID').AsInteger);
  1001. end;
  1002. procedure TTestCursorDBBasics.TestOnFilter;
  1003. var tel : byte;
  1004. begin
  1005. with DBConnector.GetNDataset(15) do
  1006. begin
  1007. OnFilterRecord := TestOnFilterProc;
  1008. Filtered := True;
  1009. Open;
  1010. for tel := 1 to 8 do
  1011. begin
  1012. CheckTrue(odd(FieldByName('ID').asinteger));
  1013. next;
  1014. end;
  1015. CheckTrue(EOF);
  1016. end;
  1017. end;
  1018. procedure TTestCursorDBBasics.TestIntFilter;
  1019. var tel : byte;
  1020. begin
  1021. with DBConnector.GetNDataset(15) do
  1022. begin
  1023. Filtered := True;
  1024. Filter := '(id>4) and (id<9)';
  1025. Open;
  1026. for tel := 5 to 8 do
  1027. begin
  1028. CheckEquals(tel,FieldByName('ID').asinteger);
  1029. next;
  1030. end;
  1031. CheckTrue(EOF);
  1032. Close;
  1033. end;
  1034. end;
  1035. procedure TTestDBBasics.TestRecordcountAfterReopen;
  1036. var
  1037. datalink1: tdatalink;
  1038. datasource1: tdatasource;
  1039. query1: TDataSet;
  1040. begin
  1041. query1:= DBConnector.GetNDataset(11);
  1042. datalink1:= TDataLink.create;
  1043. datasource1:= tdatasource.create(nil);
  1044. try
  1045. datalink1.datasource:= datasource1;
  1046. datasource1.dataset:= query1;
  1047. query1.active := true;
  1048. query1.active := False;
  1049. CheckEquals(0, THackDataLink(datalink1).RecordCount);
  1050. query1.active := true;
  1051. CheckTrue(THackDataLink(datalink1).RecordCount>0);
  1052. query1.active := false;
  1053. finally
  1054. datalink1.free;
  1055. datasource1.free;
  1056. end;
  1057. end;
  1058. procedure TTestCursorDBBasics.TestStringFilter;
  1059. var tel : byte;
  1060. begin
  1061. with DBConnector.GetNDataset(15) do
  1062. begin
  1063. Open;
  1064. Filter := '(name=''TestName3'')';
  1065. Filtered := True;
  1066. CheckFalse(EOF);
  1067. CheckEquals(3,FieldByName('ID').asinteger);
  1068. CheckEquals('TestName3',FieldByName('NAME').asstring);
  1069. next;
  1070. CheckTrue(EOF);
  1071. // Check partial compare
  1072. Filter := '(name=''*Name5'')';
  1073. CheckFalse(EOF);
  1074. CheckEquals(5,FieldByName('ID').asinteger);
  1075. CheckEquals('TestName5',FieldByName('NAME').asstring);
  1076. next;
  1077. CheckTrue(EOF);
  1078. // Check case-sensitivity
  1079. Filter := '(name=''*name3'')';
  1080. first;
  1081. CheckTrue(EOF);
  1082. FilterOptions:=[foCaseInsensitive];
  1083. Filter := '(name=''testname3'')';
  1084. first;
  1085. CheckFalse(EOF);
  1086. CheckEquals(3,FieldByName('ID').asinteger);
  1087. CheckEquals('TestName3',FieldByName('NAME').asstring);
  1088. next;
  1089. CheckTrue(EOF);
  1090. // Check case-insensitive partial compare
  1091. Filter := '(name=''*name3'')';
  1092. first;
  1093. CheckFalse(EOF);
  1094. CheckEquals(3,FieldByName('ID').asinteger);
  1095. CheckEquals('TestName3',FieldByName('NAME').asstring);
  1096. next;
  1097. CheckTrue(EOF);
  1098. Filter := '(name=''*name*'')';
  1099. first;
  1100. CheckFalse(EOF);
  1101. CheckEquals(1,FieldByName('ID').asinteger);
  1102. CheckEquals('TestName1',FieldByName('NAME').asstring);
  1103. next;
  1104. CheckFalse(EOF);
  1105. CheckEquals(2,FieldByName('ID').asinteger);
  1106. CheckEquals('TestName2',FieldByName('NAME').asstring);
  1107. Filter := '(name=''*neme*'')';
  1108. first;
  1109. CheckTrue(EOF);
  1110. Close;
  1111. end;
  1112. end;
  1113. {$ifdef fpc}
  1114. procedure TTestBufDatasetDBBasics.TestIsEmpty;
  1115. begin
  1116. with tCustombufdataset(DBConnector.GetNDataset(True,1)) do
  1117. begin
  1118. open;
  1119. delete;
  1120. Resync([]);
  1121. applyupdates;
  1122. CheckTrue(IsEmpty);
  1123. end;
  1124. end;
  1125. procedure TTestBufDatasetDBBasics.TestClosedIndexFieldNames;
  1126. var s : string;
  1127. bufds: TCustomBufDataset;
  1128. begin
  1129. bufds := DBConnector.GetNDataset(5) as TCustomBufDataset;
  1130. s := bufds.IndexFieldNames;
  1131. s := bufds.IndexName;
  1132. bufds.CompareBookmarks(nil,nil);
  1133. end;
  1134. procedure TTestBufDatasetDBBasics.TestSaveAsXML;
  1135. var ds : TDataset;
  1136. LoadDs: TCustomBufDataset;
  1137. begin
  1138. ds := DBConnector.GetNDataset(true,5);
  1139. ds.open;
  1140. TCustomBufDataset(ds).SaveToFile('test.xml');
  1141. ds.close;
  1142. LoadDs := TCustomBufDataset.Create(nil);
  1143. LoadDs.LoadFromFile('test.xml');
  1144. FTestXMLDatasetDefinition(LoadDS);
  1145. end;
  1146. procedure TTestBufDatasetDBBasics.TestFileNameProperty;
  1147. var ds1,ds2: TDataset;
  1148. LoadDs: TCustomBufDataset;
  1149. begin
  1150. ds2 := nil;
  1151. ds1 := DBConnector.GetNDataset(true,5);
  1152. try
  1153. ds1.open;
  1154. TCustomBufDataset(ds1).FileName:='test.xml';
  1155. ds1.close;
  1156. ds2 := DBConnector.GetNDataset(True,7);
  1157. TCustomBufDataset(ds2).FileName:='test.xml';
  1158. ds2.Open;
  1159. FTestXMLDatasetDefinition(Ds2);
  1160. finally
  1161. TCustomBufDataset(ds1).FileName:='';
  1162. if assigned(ds2) then
  1163. TCustomBufDataset(ds2).FileName:='';
  1164. end;
  1165. end;
  1166. procedure TTestBufDatasetDBBasics.TestClientDatasetAsMemDataset;
  1167. var ds : TCustomBufDataset;
  1168. i : integer;
  1169. begin
  1170. ds := TCustomBufDataset.Create(nil);
  1171. DS.FieldDefs.Add('ID',ftInteger);
  1172. DS.FieldDefs.Add('NAME',ftString,50);
  1173. DS.CreateDataset;
  1174. DS.Open;
  1175. for i := 1 to 10 do
  1176. begin
  1177. ds.Append;
  1178. ds.FieldByName('ID').AsInteger := i;
  1179. ds.FieldByName('NAME').AsString := 'TestName' + inttostr(i);
  1180. DS.Post;
  1181. end;
  1182. ds.first;
  1183. for i := 1 to 10 do
  1184. begin
  1185. CheckEquals(i,ds.fieldbyname('ID').asinteger);
  1186. CheckEquals('TestName' + inttostr(i),ds.fieldbyname('NAME').AsString);
  1187. ds.next;
  1188. end;
  1189. CheckTrue(ds.EOF);
  1190. DS.Close;
  1191. end;
  1192. procedure TTestBufDatasetDBBasics.TestBufDatasetCancelUpd;
  1193. var i : byte;
  1194. begin
  1195. with DBConnector.GetNDataset(5) as TCustomBufDataset do
  1196. begin
  1197. open;
  1198. next;
  1199. next;
  1200. edit;
  1201. FieldByName('name').AsString := 'changed';
  1202. post;
  1203. next;
  1204. delete;
  1205. CancelUpdates;
  1206. First;
  1207. for i := 1 to 5 do
  1208. begin
  1209. CheckEquals(i,fields[0].AsInteger);
  1210. CheckEquals('TestName'+inttostr(i),fields[1].AsString);
  1211. Next;
  1212. end;
  1213. end;
  1214. end;
  1215. procedure TTestBufDatasetDBBasics.TestBufDatasetCancelUpd1;
  1216. var i : byte;
  1217. begin
  1218. with DBConnector.GetNDataset(5) as TCustomBufDataset do
  1219. begin
  1220. open;
  1221. next;
  1222. next;
  1223. delete;
  1224. insert;
  1225. FieldByName('id').AsInteger := 100;
  1226. post;
  1227. CancelUpdates;
  1228. last;
  1229. for i := 5 downto 1 do
  1230. begin
  1231. CheckEquals(i,fields[0].AsInteger);
  1232. CheckEquals('TestName'+inttostr(i),fields[1].AsString);
  1233. Prior;
  1234. end;
  1235. end;
  1236. end;
  1237. procedure TTestBufDatasetDBBasics.TestMultipleDeleteUpdateBuffer;
  1238. var ds : TDataset;
  1239. begin
  1240. ds := DBConnector.GetNDataset(true,5);
  1241. ds.open;
  1242. with TCustomBufDataset(ds) do
  1243. begin
  1244. CheckEquals(0,ChangeCount);
  1245. edit;
  1246. fieldbyname('id').asinteger := 500;
  1247. fieldbyname('name').AsString := 'JoJo';
  1248. post;
  1249. CheckEquals(1,ChangeCount);
  1250. next; next;
  1251. Delete;
  1252. CheckEquals(2,ChangeCount);
  1253. Delete;
  1254. CheckEquals(3,ChangeCount);
  1255. CancelUpdates;
  1256. end;
  1257. ds.close;
  1258. end;
  1259. procedure TTestBufDatasetDBBasics.TestDoubleDelete;
  1260. var ds : TCustomBufDataset;
  1261. begin
  1262. ds := TCustomBufDataset(DBConnector.GetNDataset(true,5));
  1263. with ds do
  1264. begin
  1265. open;
  1266. next; next;
  1267. Delete;
  1268. Delete;
  1269. first;
  1270. CheckEquals(1,fieldbyname('id').AsInteger);
  1271. next;
  1272. CheckEquals(2,fieldbyname('id').AsInteger);
  1273. next;
  1274. CheckEquals(5,fieldbyname('id').AsInteger);
  1275. CancelUpdates;
  1276. first;
  1277. CheckEquals(1,fieldbyname('id').AsInteger);
  1278. next;
  1279. CheckEquals(2,fieldbyname('id').AsInteger);
  1280. next;
  1281. CheckEquals(3,fieldbyname('id').AsInteger);
  1282. next;
  1283. CheckEquals(4,fieldbyname('id').AsInteger);
  1284. next;
  1285. CheckEquals(5,fieldbyname('id').AsInteger);
  1286. end;
  1287. end;
  1288. procedure TTestBufDatasetDBBasics.TestReadOnly;
  1289. var
  1290. ds: TCustomBufDataset;
  1291. begin
  1292. ds := DBConnector.GetFieldDataset as TCustomBufDataset;
  1293. with ds do
  1294. begin
  1295. ReadOnly:=true;
  1296. CheckFalse(CanModify);
  1297. end;
  1298. end;
  1299. procedure TTestBufDatasetDBBasics.TestMergeChangeLog;
  1300. var
  1301. ds: TCustomBufDataset;
  1302. i: integer;
  1303. s: string;
  1304. begin
  1305. ds := DBConnector.GetNDataset(5) as TCustomBufDataset;
  1306. with ds do
  1307. begin
  1308. open;
  1309. Edit;
  1310. i := fields[0].AsInteger;
  1311. s := fields[1].AsString;
  1312. fields[0].AsInteger:=64;
  1313. fields[1].AsString:='Changed';
  1314. Post;
  1315. checkequals(fields[0].OldValue,i);
  1316. checkequals(fields[1].OldValue,s);
  1317. CheckEquals(ChangeCount,1);
  1318. MergeChangeLog;
  1319. CheckEquals(ChangeCount,0);
  1320. checkequals(fields[0].OldValue,64);
  1321. checkequals(fields[1].OldValue,'Changed');
  1322. end;
  1323. end;
  1324. procedure TTestBufDatasetDBBasics.FTestXMLDatasetDefinition(ADataset: TDataset);
  1325. var i : integer;
  1326. begin
  1327. CheckEquals(2,ADataset.FieldDefs.Count);
  1328. CheckEquals(2,ADataset.Fields.Count);
  1329. CheckTrue(SameText('ID',ADataset.Fields[0].FieldName));
  1330. CheckTrue(SameText('NAME',ADataset.Fields[1].FieldName));
  1331. CheckEquals(ord(ftString), ord(ADataset.Fields[1].DataType), 'Incorrect FieldType');
  1332. i := 1;
  1333. while not ADataset.EOF do
  1334. begin
  1335. CheckEquals('TestName'+inttostr(i),ADataset.FieldByName('name').AsString);
  1336. ADataset.Next;
  1337. inc(i);
  1338. end;
  1339. end;
  1340. procedure TTestBufDatasetDBBasics.TestAddIndexFieldType(AFieldType: TFieldType; ActiveDS : boolean);
  1341. var ds : TCustomBufDataset;
  1342. FList : TStringList;
  1343. LastValue : Variant;
  1344. StrValue : String;
  1345. begin
  1346. ds := DBConnector.GetFieldDataset as TCustomBufDataset;
  1347. with ds do
  1348. begin
  1349. if not ActiveDS then
  1350. begin
  1351. AddIndex('testindex','F'+FieldTypeNames[AfieldType],[]);
  1352. IndexName:='testindex';
  1353. end
  1354. else
  1355. MaxIndexesCount := 3;
  1356. try
  1357. open;
  1358. except
  1359. if not assigned(ds.FindField('F'+FieldTypeNames[AfieldType])) then
  1360. Ignore('Fields of the type ' + FieldTypeNames[AfieldType] + ' are not supported by this type of dataset')
  1361. else
  1362. raise;
  1363. end;
  1364. if ActiveDS then
  1365. begin
  1366. if not assigned(ds.FindField('F'+FieldTypeNames[AfieldType])) then
  1367. Ignore('Fields of the type ' + FieldTypeNames[AfieldType] + ' are not supported by this type of dataset');
  1368. AddIndex('testindex','F'+FieldTypeNames[AfieldType],[]);
  1369. IndexName:='testindex';
  1370. First;
  1371. end;
  1372. LastValue:=null;
  1373. while not eof do
  1374. begin
  1375. if AFieldType=ftString then
  1376. CheckTrue(AnsiCompareStr(VarToStr(LastValue),VarToStr(FieldByName('F'+FieldTypeNames[AfieldType]).AsString))<=0)
  1377. else
  1378. CheckTrue(LastValue<=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant);
  1379. LastValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant;
  1380. Next;
  1381. end;
  1382. while not bof do
  1383. begin
  1384. if AFieldType=ftString then
  1385. CheckTrue(AnsiCompareStr(VarToStr(LastValue),VarToStr(FieldByName('F'+FieldTypeNames[AfieldType]).AsString))>=0)
  1386. else
  1387. CheckTrue(LastValue>=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant);
  1388. LastValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant;
  1389. Prior;
  1390. end;
  1391. end;
  1392. end;
  1393. procedure TTestBufDatasetDBBasics.TestAddIndexSmallInt;
  1394. begin
  1395. TestAddIndexFieldType(ftSmallint,False);
  1396. end;
  1397. procedure TTestBufDatasetDBBasics.TestAddIndexBoolean;
  1398. begin
  1399. TestAddIndexFieldType(ftBoolean,False);
  1400. end;
  1401. procedure TTestBufDatasetDBBasics.TestAddIndexFloat;
  1402. begin
  1403. TestAddIndexFieldType(ftFloat,False);
  1404. end;
  1405. procedure TTestBufDatasetDBBasics.TestAddIndexInteger;
  1406. begin
  1407. TestAddIndexFieldType(ftInteger,False);
  1408. end;
  1409. procedure TTestBufDatasetDBBasics.TestAddIndexLargeInt;
  1410. begin
  1411. TestAddIndexFieldType(ftLargeint,False);
  1412. end;
  1413. procedure TTestBufDatasetDBBasics.TestAddIndexDateTime;
  1414. begin
  1415. TestAddIndexFieldType(ftDateTime,False);
  1416. end;
  1417. procedure TTestBufDatasetDBBasics.TestAddIndexCurrency;
  1418. begin
  1419. TestAddIndexFieldType(ftCurrency,False);
  1420. end;
  1421. procedure TTestBufDatasetDBBasics.TestAddIndexBCD;
  1422. begin
  1423. TestAddIndexFieldType(ftBCD,False);
  1424. end;
  1425. procedure TTestBufDatasetDBBasics.TestAddIndex;
  1426. var ds : TCustomBufDataset;
  1427. AFieldType : TFieldType;
  1428. FList : TStringList;
  1429. i : integer;
  1430. begin
  1431. ds := DBConnector.GetFieldDataset as TCustomBufDataset;
  1432. with ds do
  1433. begin
  1434. AFieldType:=ftString;
  1435. AddIndex('testindex','F'+FieldTypeNames[AfieldType],[]);
  1436. FList := TStringList.Create;
  1437. FList.Sorted:=true;
  1438. FList.CaseSensitive:=True;
  1439. FList.Duplicates:=dupAccept;
  1440. open;
  1441. while not eof do
  1442. begin
  1443. flist.Add(FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1444. Next;
  1445. end;
  1446. IndexName:='testindex';
  1447. first;
  1448. i:=0;
  1449. while not eof do
  1450. begin
  1451. CheckEquals(flist[i],FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1452. inc(i);
  1453. Next;
  1454. end;
  1455. while not bof do
  1456. begin
  1457. dec(i);
  1458. CheckEquals(flist[i],FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1459. Prior;
  1460. end;
  1461. end;
  1462. end;
  1463. procedure TTestBufDatasetDBBasics.TestAddDescIndex;
  1464. var ds : TCustomBufDataset;
  1465. AFieldType : TFieldType;
  1466. FList : TStringList;
  1467. i : integer;
  1468. begin
  1469. ds := DBConnector.GetFieldDataset as TCustomBufDataset;
  1470. with ds do
  1471. begin
  1472. AFieldType:=ftString;
  1473. AddIndex('testindex','F'+FieldTypeNames[AfieldType],[],'F'+FieldTypeNames[AfieldType]);
  1474. FList := TStringList.Create;
  1475. FList.Sorted:=true;
  1476. FList.CaseSensitive:=True;
  1477. FList.Duplicates:=dupAccept;
  1478. open;
  1479. while not eof do
  1480. begin
  1481. flist.Add(FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1482. Next;
  1483. end;
  1484. IndexName:='testindex';
  1485. first;
  1486. i:=FList.Count-1;
  1487. while not eof do
  1488. begin
  1489. CheckEquals(flist[i],FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1490. dec(i);
  1491. Next;
  1492. end;
  1493. while not bof do
  1494. begin
  1495. inc(i);
  1496. CheckEquals(flist[i],FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1497. Prior;
  1498. end;
  1499. end;
  1500. end;
  1501. procedure TTestBufDatasetDBBasics.TestAddCaseInsIndex;
  1502. var ds : TCustomBufDataset;
  1503. AFieldType : TFieldType;
  1504. FList : TStringList;
  1505. i : integer;
  1506. begin
  1507. ds := DBConnector.GetFieldDataset as TCustomBufDataset;
  1508. with ds do
  1509. begin
  1510. AFieldType:=ftString;
  1511. AddIndex('testindex','F'+FieldTypeNames[AfieldType],[],'','F'+FieldTypeNames[AfieldType]);
  1512. FList := TStringList.Create;
  1513. FList.Sorted:=true;
  1514. FList.Duplicates:=dupAccept;
  1515. open;
  1516. while not eof do
  1517. begin
  1518. flist.Add(FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1519. Next;
  1520. end;
  1521. IndexName:='testindex';
  1522. first;
  1523. i:=0;
  1524. while not eof do
  1525. begin
  1526. CheckEquals(flist[i],FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1527. inc(i);
  1528. Next;
  1529. end;
  1530. while not bof do
  1531. begin
  1532. dec(i);
  1533. CheckEquals(flist[i],FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1534. Prior;
  1535. end;
  1536. end;
  1537. end;
  1538. procedure TTestBufDatasetDBBasics.TestInactSwitchIndex;
  1539. // Test if the default-index is properly build when the active index is not
  1540. // the default-index while opening then dataset
  1541. var ds : TCustomBufDataset;
  1542. AFieldType : TFieldType;
  1543. i : integer;
  1544. begin
  1545. ds := DBConnector.GetFieldDataset as TCustomBufDataset;
  1546. with ds do
  1547. begin
  1548. AFieldType:=ftString;
  1549. AddIndex('testindex','F'+FieldTypeNames[AfieldType],[]);
  1550. IndexName:='testindex';
  1551. open;
  1552. IndexName:=''; // This should set the default index (default_order)
  1553. first;
  1554. i := 0;
  1555. while not eof do
  1556. begin
  1557. CheckEquals(testStringValues[i],FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1558. inc(i);
  1559. Next;
  1560. end;
  1561. end;
  1562. end;
  1563. procedure TTestBufDatasetDBBasics.TestAddIndexActiveDS;
  1564. var ds : TCustomBufDataset;
  1565. I : integer;
  1566. begin
  1567. TestAddIndexFieldType(ftString,true);
  1568. end;
  1569. procedure TTestBufDatasetDBBasics.TestAddIndexEditDS;
  1570. var ds : TCustomBufDataset;
  1571. I : integer;
  1572. LastValue : String;
  1573. begin
  1574. ds := DBConnector.GetNDataset(True,5) as TCustomBufDataset;
  1575. with ds do
  1576. begin
  1577. MaxIndexesCount:=3;
  1578. open;
  1579. edit;
  1580. FieldByName('name').asstring := 'Zz';
  1581. post;
  1582. next;
  1583. next;
  1584. edit;
  1585. FieldByName('name').asstring := 'aA';
  1586. post;
  1587. AddIndex('test','name',[]);
  1588. first;
  1589. ds.IndexName:='test';
  1590. first;
  1591. LastValue:='';
  1592. while not eof do
  1593. begin
  1594. CheckTrue(AnsiCompareStr(LastValue,FieldByName('name').AsString)<=0);
  1595. LastValue:=FieldByName('name').AsString;
  1596. Next;
  1597. end;
  1598. end;
  1599. end;
  1600. procedure TTestBufDatasetDBBasics.TestIndexFieldNamesAct;
  1601. var ds : TCustomBufDataset;
  1602. AFieldType : TFieldType;
  1603. FList : TStringList;
  1604. i : integer;
  1605. begin
  1606. ds := DBConnector.GetFieldDataset as TCustomBufDataset;
  1607. with ds do
  1608. begin
  1609. AFieldType:=ftString;
  1610. FList := TStringList.Create;
  1611. FList.Sorted:=true;
  1612. FList.CaseSensitive:=True;
  1613. FList.Duplicates:=dupAccept;
  1614. open;
  1615. while not eof do
  1616. begin
  1617. flist.Add(FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1618. Next;
  1619. end;
  1620. IndexFieldNames:='F'+FieldTypeNames[AfieldType];
  1621. first;
  1622. i:=0;
  1623. while not eof do
  1624. begin
  1625. CheckEquals(flist[i],FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1626. inc(i);
  1627. Next;
  1628. end;
  1629. while not bof do
  1630. begin
  1631. dec(i);
  1632. CheckEquals(flist[i],FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1633. Prior;
  1634. end;
  1635. CheckEquals('F'+FieldTypeNames[AfieldType],IndexFieldNames);
  1636. IndexFieldNames:='ID';
  1637. first;
  1638. i:=0;
  1639. while not eof do
  1640. begin
  1641. CheckEquals(testStringValues[i],FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1642. inc(i);
  1643. Next;
  1644. end;
  1645. CheckEquals('ID',IndexFieldNames);
  1646. IndexFieldNames:='';
  1647. first;
  1648. i:=0;
  1649. while not eof do
  1650. begin
  1651. CheckEquals(testStringValues[i],FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1652. inc(i);
  1653. Next;
  1654. end;
  1655. CheckEquals('',IndexFieldNames);
  1656. end;
  1657. end;
  1658. procedure TTestBufDatasetDBBasics.TestIndexCurRecord;
  1659. // Test if the currentrecord stays the same after an index change
  1660. var ds : TCustomBufDataset;
  1661. AFieldType : TFieldType;
  1662. i : integer;
  1663. OldID : Integer;
  1664. OldStringValue : string;
  1665. begin
  1666. ds := DBConnector.GetFieldDataset as TCustomBufDataset;
  1667. with ds do
  1668. begin
  1669. AFieldType:=ftString;
  1670. AddIndex('testindex','F'+FieldTypeNames[AfieldType],[]);
  1671. open;
  1672. for i := 0 to (testValuesCount div 3) do
  1673. Next;
  1674. OldID:=FieldByName('id').AsInteger;
  1675. OldStringValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsString;
  1676. IndexName:='testindex';
  1677. CheckEquals(OldID,FieldByName('id').AsInteger);
  1678. CheckEquals(OldStringValue,FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1679. next;
  1680. CheckTrue(OldStringValue<=FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1681. prior;
  1682. prior;
  1683. CheckTrue(OldStringValue>=FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1684. OldID:=FieldByName('id').AsInteger;
  1685. OldStringValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsString;
  1686. IndexName:='';
  1687. CheckEquals(OldID,FieldByName('id').AsInteger);
  1688. CheckEquals(OldStringValue,FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
  1689. next;
  1690. CheckEquals(OldID+1,FieldByName('ID').AsInteger);
  1691. prior;
  1692. prior;
  1693. CheckEquals(OldID-1,FieldByName('ID').AsInteger);
  1694. end;
  1695. end;
  1696. procedure TTestBufDatasetDBBasics.TestAddDblIndex;
  1697. var ds : TCustomBufDataset;
  1698. LastInteger : Integer;
  1699. LastString : string;
  1700. begin
  1701. ds := DBConnector.GetFieldDataset as TCustomBufDataset;
  1702. with ds do
  1703. begin
  1704. AddIndex('testindex','F'+FieldTypeNames[ftString]+';F'+FieldTypeNames[ftInteger],[]);
  1705. open;
  1706. IndexName:='testindex';
  1707. first;
  1708. LastString:='';
  1709. while not eof do
  1710. begin
  1711. CheckTrue(AnsiCompareStr(FieldByName('F'+FieldTypeNames[ftString]).AsString,LastString)>=0);
  1712. LastString:= FieldByName('F'+FieldTypeNames[ftString]).AsString;
  1713. LastInteger:=-MaxInt;
  1714. while (FieldByName('F'+FieldTypeNames[ftString]).AsString=LastString) and not eof do
  1715. begin
  1716. CheckTrue(FieldByName('F'+FieldTypeNames[ftInteger]).AsInteger>=LastInteger);
  1717. LastInteger:=FieldByName('F'+FieldTypeNames[ftInteger]).AsInteger;
  1718. next;
  1719. end;
  1720. end;
  1721. while not bof do
  1722. begin
  1723. CheckTrue(AnsiCompareStr(FieldByName('F'+FieldTypeNames[ftString]).AsString,LastString)<=0);
  1724. LastString:= FieldByName('F'+FieldTypeNames[ftString]).AsString;
  1725. LastInteger:=+MaxInt;
  1726. while (FieldByName('F'+FieldTypeNames[ftString]).AsString=LastString) and not bof do
  1727. begin
  1728. CheckTrue(FieldByName('F'+FieldTypeNames[ftInteger]).AsInteger<=LastInteger);
  1729. LastInteger:=FieldByName('F'+FieldTypeNames[ftInteger]).AsInteger;
  1730. prior;
  1731. end;
  1732. end;
  1733. end;
  1734. end;
  1735. procedure TTestBufDatasetDBBasics.TestIndexEditRecord;
  1736. // Tests index sorting for string field type by
  1737. // editing an existing record in the middle
  1738. // with a value at the end of the alphabet
  1739. var ds : TCustomBufDataset;
  1740. AFieldType : TFieldType;
  1741. i : integer;
  1742. OldID : Integer;
  1743. OldStringValue : string;
  1744. begin
  1745. ds := DBConnector.GetFieldDataset as TCustomBufDataset;
  1746. with ds do
  1747. begin
  1748. AFieldType:=ftString;
  1749. AddIndex('testindex','F'+FieldTypeNames[AfieldType],[]);
  1750. IndexName:='testindex';
  1751. open; //Record 0
  1752. OldStringValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsString;
  1753. next; //Now on record 1
  1754. CheckTrue(OldStringValue<=FieldByName('F'+FieldTypeNames[AfieldType]).AsString,'Record 0 must be smaller than record 1 with asc sorted index');
  1755. OldStringValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsString;
  1756. next; //Now on record 2
  1757. CheckTrue(AnsiCompareStr(OldStringValue,FieldByName('F'+FieldTypeNames[AfieldType]).AsString)<=0,'Record 1 must be smaller than record 2 with asc sorted index');
  1758. prior; //Now on record 1
  1759. edit;
  1760. FieldByName('F'+FieldTypeNames[AfieldType]).AsString := 'ZZZ'; //should be sorted last
  1761. post;
  1762. prior; // Now on record 0
  1763. // Check ZZZ is sorted on/after record 0
  1764. CheckTrue(AnsiCompareStr('ZZZ',FieldByName('F'+FieldTypeNames[AfieldType]).AsString)>=0, 'Prior>');
  1765. next;
  1766. next; // Now on record 2
  1767. // Check ZZZ is sorted on/before record 2
  1768. CheckTrue(AnsiCompareStr('ZZZ',FieldByName('F'+FieldTypeNames[AfieldType]).AsString)<=0, 'Next<');
  1769. close;
  1770. end;
  1771. end;
  1772. procedure TTestBufDatasetDBBasics.TestIndexAppendRecord;
  1773. var i: integer;
  1774. LastValue: string;
  1775. begin
  1776. with DBConnector.GetNDataset(true,0) as TCustomBufDataset do
  1777. begin
  1778. MaxIndexesCount:=4;
  1779. // add index to closed dataset with no data
  1780. AddIndex('testindex','NAME',[]);
  1781. IndexName:='testindex';
  1782. Open;
  1783. // empty dataset and other than default index (default_order) active
  1784. CheckTrue(BOF, 'No BOF when opening empty dataset');
  1785. CheckTrue(EOF, 'No EOF when opening empty dataset');
  1786. // append data at end
  1787. for i:=20 downto 0 do
  1788. AppendRecord([i, inttostr(i)]);
  1789. First;
  1790. // insert data at begining
  1791. for i:=21 to 22 do
  1792. InsertRecord([i, inttostr(i)]);
  1793. // ATM new records are not ordered as they are added ?
  1794. LastValue := '';
  1795. First;
  1796. for i:=22 downto 0 do
  1797. begin
  1798. CheckEquals(23-i, RecNo, 'testindex.RecNo:');
  1799. CheckEquals(inttostr(i), Fields[1].AsString, 'testindex.Fields[1].Value:');
  1800. //CheckTrue(AnsiCompareStr(LastValue,Fields[1].AsString) < 0, 'testindex.LastValue>CurrValue');
  1801. LastValue := Fields[1].AsString;
  1802. Next;
  1803. end;
  1804. CheckTrue(EOF, 'testindex.No EOF after last record');
  1805. // switch back to default index (unordered)
  1806. IndexName:='';
  1807. First;
  1808. for i:=22 downto 0 do
  1809. begin
  1810. CheckEquals(23-i, RecNo, 'index[0].RecNo:');
  1811. CheckEquals(i, Fields[0].AsInteger, 'index[0].Fields[0].Value:');
  1812. Next;
  1813. end;
  1814. CheckTrue(EOF, 'index[0].No EOF after last record');
  1815. // add index to opened dataset with data
  1816. AddIndex('testindex2','ID',[]);
  1817. IndexName:='testindex2';
  1818. First;
  1819. for i:=0 to 22 do
  1820. begin
  1821. CheckEquals(1+i, RecNo, 'index2.RecNo:');
  1822. CheckEquals(i, Fields[0].AsInteger, 'index2.Fields[0].Value:');
  1823. Next;
  1824. end;
  1825. CheckTrue(EOF, 'index2.No EOF after last record');
  1826. Close;
  1827. end;
  1828. end;
  1829. procedure TTestBufDatasetDBBasics.TestIndexFieldNames;
  1830. var ds : TCustomBufDataset;
  1831. AFieldType : TFieldType;
  1832. PrevValue : String;
  1833. begin
  1834. ds := DBConnector.GetFieldDataset as TCustomBufDataset;
  1835. with ds do
  1836. begin
  1837. AFieldType:=ftString;
  1838. IndexFieldNames:='F'+FieldTypeNames[AfieldType];
  1839. open;
  1840. PrevValue:='';
  1841. while not eof do
  1842. begin
  1843. CheckTrue(AnsiCompareStr(FieldByName('F'+FieldTypeNames[AfieldType]).AsString,PrevValue)>=0);
  1844. PrevValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsString;
  1845. Next;
  1846. end;
  1847. CheckEquals('F'+FieldTypeNames[AfieldType],IndexFieldNames);
  1848. end;
  1849. end;
  1850. {$endif fpc}
  1851. procedure TTestDBBasics.TestcalculatedField_OnCalcfields(DataSet: TDataSet);
  1852. begin
  1853. case dataset.fieldbyname('ID').asinteger of
  1854. 1 : dataset.fieldbyname('CALCFLD').AsInteger := 5;
  1855. 2 : dataset.fieldbyname('CALCFLD').AsInteger := 70000;
  1856. 3 : dataset.fieldbyname('CALCFLD').Clear;
  1857. 4 : dataset.fieldbyname('CALCFLD').AsInteger := 1234;
  1858. 10 : dataset.fieldbyname('CALCFLD').Clear;
  1859. else
  1860. dataset.fieldbyname('CALCFLD').AsInteger := 1;
  1861. end;
  1862. end;
  1863. procedure TTestDBBasics.TestCalculatedField;
  1864. var ds : TDataset;
  1865. AFld1, AFld2, AFld3 : Tfield;
  1866. begin
  1867. ds := DBConnector.GetNDataset(5);
  1868. with ds do
  1869. begin
  1870. AFld1 := TIntegerField.Create(ds);
  1871. AFld1.FieldName := 'ID';
  1872. AFld1.DataSet := ds;
  1873. AFld2 := TStringField.Create(ds);
  1874. AFld2.FieldName := 'NAME';
  1875. AFld2.DataSet := ds;
  1876. AFld3 := TIntegerField.Create(ds);
  1877. AFld3.FieldName := 'CALCFLD';
  1878. AFld3.DataSet := ds;
  1879. Afld3.FieldKind := fkCalculated;
  1880. CheckEquals(3,FieldCount);
  1881. ds.OnCalcFields := TestcalculatedField_OnCalcfields;
  1882. open;
  1883. CheckEquals(1,FieldByName('ID').asinteger);
  1884. CheckEquals(5,FieldByName('CALCFLD').asinteger);
  1885. next;
  1886. CheckEquals(70000,FieldByName('CALCFLD').asinteger);
  1887. next;
  1888. CheckEquals(true,FieldByName('CALCFLD').isnull);
  1889. next;
  1890. CheckEquals(1234,FieldByName('CALCFLD').AsInteger);
  1891. edit;
  1892. FieldByName('ID').AsInteger := 10;
  1893. post;
  1894. CheckEquals(true,FieldByName('CALCFLD').isnull);
  1895. close;
  1896. AFld1.Free;
  1897. AFld2.Free;
  1898. AFld3.Free;
  1899. end;
  1900. end;
  1901. procedure TTestCursorDBBasics.TestEofAfterFirst;
  1902. begin
  1903. with DBConnector.GetNDataset(0) do
  1904. begin
  1905. open;
  1906. CheckTrue(eof);
  1907. CheckTrue(BOF);
  1908. first;
  1909. CheckTrue(eof);
  1910. CheckTrue(BOF);
  1911. end;
  1912. end;
  1913. procedure TTestDBBasics.TestfieldDefinition(AFieldType : TFieldType;ADatasize : integer;var ADS : TDataset; var AFld: TField);
  1914. var i : byte;
  1915. begin
  1916. ADS := DBConnector.GetFieldDataset;
  1917. ADS.Open;
  1918. AFld := ADS.FindField('F'+FieldTypeNames[AfieldType]);
  1919. {$ifdef fpc}
  1920. if not assigned (AFld) then
  1921. Ignore('Fields of the type ' + FieldTypeNames[AfieldType] + ' are not supported by this type of dataset');
  1922. {$endif fpc}
  1923. CheckEquals(ord(AFieldType), ord(AFld.DataType), 'DataType');
  1924. CheckEquals(ADatasize, AFld.DataSize, 'DataSize');
  1925. end;
  1926. procedure TTestDBBasics.TestSupportIntegerFields;
  1927. var i : byte;
  1928. ds : TDataset;
  1929. Fld : TField;
  1930. begin
  1931. TestfieldDefinition(ftInteger,4,ds,Fld);
  1932. for i := 0 to testValuesCount-1 do
  1933. begin
  1934. CheckEquals(testIntValues[i],Fld.AsInteger);
  1935. ds.Next;
  1936. end;
  1937. ds.close;
  1938. end;
  1939. procedure TTestDBBasics.TestSupportSmallIntFields;
  1940. var i : byte;
  1941. ds : TDataset;
  1942. Fld : TField;
  1943. begin
  1944. TestfieldDefinition(ftSmallint,2,ds,Fld);
  1945. for i := 0 to testValuesCount-1 do
  1946. begin
  1947. CheckEquals(testSmallIntValues[i],Fld.AsInteger);
  1948. ds.Next;
  1949. end;
  1950. ds.close;
  1951. end;
  1952. procedure TTestDBBasics.TestSupportStringFields;
  1953. var i : byte;
  1954. ds : TDataset;
  1955. Fld : TField;
  1956. begin
  1957. TestfieldDefinition(ftString,11,ds,Fld);
  1958. for i := 0 to testValuesCount-1 do
  1959. begin
  1960. CheckEquals(testStringValues[i],Fld.AsString);
  1961. ds.Next;
  1962. end;
  1963. ds.close;
  1964. end;
  1965. procedure TTestDBBasics.TestSupportBooleanFields;
  1966. var i : byte;
  1967. ds : TDataset;
  1968. Fld : TField;
  1969. begin
  1970. TestfieldDefinition(ftBoolean,2,ds,Fld);
  1971. for i := 0 to testValuesCount-1 do
  1972. begin
  1973. CheckEquals(testBooleanValues[i],Fld.AsBoolean);
  1974. ds.Next;
  1975. end;
  1976. ds.close;
  1977. end;
  1978. procedure TTestDBBasics.TestSupportFloatFields;
  1979. var i : byte;
  1980. ds : TDataset;
  1981. Fld : TField;
  1982. begin
  1983. TestfieldDefinition(ftFloat,8,ds,Fld);
  1984. for i := 0 to testValuesCount-1 do
  1985. begin
  1986. CheckEquals(testFloatValues[i],Fld.AsFloat);
  1987. ds.Next;
  1988. end;
  1989. ds.close;
  1990. end;
  1991. procedure TTestDBBasics.TestSupportLargeIntFields;
  1992. var i : byte;
  1993. ds : TDataset;
  1994. Fld : TField;
  1995. begin
  1996. TestfieldDefinition(ftLargeint,8,ds,Fld);
  1997. for i := 0 to testValuesCount-1 do
  1998. begin
  1999. CheckEquals(testLargeIntValues[i],Fld.AsLargeInt);
  2000. ds.Next;
  2001. end;
  2002. ds.close;
  2003. end;
  2004. procedure TTestDBBasics.TestSupportDateFields;
  2005. var i : byte;
  2006. ds : TDataset;
  2007. Fld : TField;
  2008. begin
  2009. TestfieldDefinition(ftDate,8,ds,Fld);
  2010. for i := 0 to testValuesCount-1 do
  2011. begin
  2012. CheckEquals(testDateValues[i], FormatDateTime('yyyy/mm/dd', Fld.AsDateTime, DBConnector.FormatSettings));
  2013. ds.Next;
  2014. end;
  2015. ds.close;
  2016. end;
  2017. procedure TTestDBBasics.TestSupportTimeFields;
  2018. var i : byte;
  2019. ds : TDataset;
  2020. Fld : TField;
  2021. begin
  2022. TestfieldDefinition(ftTime,8,ds,Fld);
  2023. for i := 0 to testValuesCount-1 do
  2024. begin
  2025. CheckEquals(testTimeValues[i],DateTimeToTimeString(fld.AsDateTime));
  2026. ds.Next;
  2027. end;
  2028. ds.close;
  2029. end;
  2030. procedure TTestDBBasics.TestSupportCurrencyFields;
  2031. var i : byte;
  2032. ds : TDataset;
  2033. Fld : TField;
  2034. begin
  2035. TestfieldDefinition(ftCurrency,8,ds,Fld);
  2036. for i := 0 to testValuesCount-1 do
  2037. begin
  2038. CheckEquals(testCurrencyValues[i],Fld.AsCurrency);
  2039. CheckEquals(testCurrencyValues[i],Fld.AsFloat);
  2040. ds.Next;
  2041. end;
  2042. ds.close;
  2043. end;
  2044. procedure TTestDBBasics.TestSupportBCDFields;
  2045. var i : byte;
  2046. ds : TDataset;
  2047. Fld : TField;
  2048. begin
  2049. TestfieldDefinition(ftBCD,8,ds,Fld);
  2050. for i := 0 to testValuesCount-1 do
  2051. begin
  2052. CheckEquals(CurrToStr(testCurrencyValues[i]),Fld.AsString);
  2053. CheckEquals(testCurrencyValues[i],Fld.AsCurrency);
  2054. CheckEquals(testCurrencyValues[i],Fld.AsFloat);
  2055. ds.Next;
  2056. end;
  2057. ds.close;
  2058. end;
  2059. procedure TTestDBBasics.TestSupportfmtBCDFields;
  2060. var i : byte;
  2061. ds : TDataset;
  2062. Fld : TField;
  2063. begin
  2064. TestfieldDefinition(ftFMTBcd,sizeof(TBCD),ds,Fld);
  2065. for i := 0 to testValuesCount-1 do
  2066. begin
  2067. CheckEquals(testFmtBCDValues[i], BCDToStr(Fld.AsBCD,DBConnector.FormatSettings));
  2068. CheckEquals(StrToFloat(testFmtBCDValues[i],DBConnector.FormatSettings), Fld.AsFloat);
  2069. ds.Next;
  2070. end;
  2071. ds.close;
  2072. end;
  2073. procedure TTestDBBasics.TestSupportFixedStringFields;
  2074. var i : byte;
  2075. ds : TDataset;
  2076. Fld : TField;
  2077. begin
  2078. TestfieldDefinition(ftFixedChar,11,ds,Fld);
  2079. for i := 0 to testValuesCount-1 do
  2080. begin
  2081. if Fld.IsNull then // If the field is null, .AsString always returns an empty, non-padded string
  2082. CheckEquals(testStringValues[i],Fld.AsString)
  2083. else
  2084. {$ifdef fpc}
  2085. CheckEquals(PadRight(testStringValues[i],10),Fld.AsString);
  2086. {$else fpc}
  2087. CheckEquals(testStringValues[i],Fld.AsString);
  2088. {$endif fpc}
  2089. ds.Next;
  2090. end;
  2091. ds.close;
  2092. end;
  2093. procedure TTestDBBasics.TestSupportBlobFields;
  2094. var i : byte;
  2095. ds : TDataset;
  2096. Fld : TField;
  2097. begin
  2098. TestfieldDefinition(ftBlob,0,ds,Fld);
  2099. for i := 0 to testValuesCount-1 do
  2100. begin
  2101. CheckEquals(testValues[ftBlob,i],Fld.AsString);
  2102. ds.Next;
  2103. end;
  2104. ds.close;
  2105. end;
  2106. procedure TTestDBBasics.TestSupportMemoFields;
  2107. var i : byte;
  2108. ds : TDataset;
  2109. Fld : TField;
  2110. begin
  2111. TestfieldDefinition(ftMemo,0,ds,Fld);
  2112. for i := 0 to testValuesCount-1 do
  2113. begin
  2114. CheckEquals(testValues[ftMemo,i],Fld.AsString);
  2115. ds.Next;
  2116. end;
  2117. ds.close;
  2118. end;
  2119. procedure TTestDBBasics.TestDoubleClose;
  2120. begin
  2121. with DBConnector.GetNDataset(1) do
  2122. begin
  2123. close;
  2124. close;
  2125. open;
  2126. close;
  2127. close;
  2128. end;
  2129. end;
  2130. procedure TTestDBBasics.TestAssignFieldftString;
  2131. var AParam : TParam;
  2132. AField : TField;
  2133. begin
  2134. AParam := TParam.Create(nil);
  2135. with DBConnector.GetNDataset(1) do
  2136. begin
  2137. open;
  2138. AField := fieldbyname('name');
  2139. AParam.AssignField(AField);
  2140. CheckEquals(ord(ftString), ord(AParam.DataType), 'DataType');
  2141. close;
  2142. end;
  2143. AParam.Free;
  2144. end;
  2145. procedure TTestDBBasics.TestAssignFieldftFixedChar;
  2146. var AParam : TParam;
  2147. AField : TField;
  2148. begin
  2149. AParam := TParam.Create(nil);
  2150. with DBConnector.GetNDataset(1) do
  2151. begin
  2152. open;
  2153. AField := fieldbyname('name');
  2154. (AField as tstringfield).FixedChar := true;
  2155. AParam.AssignField(AField);
  2156. CheckEquals(ord(ftFixedChar), ord(AParam.DataType), 'DataType');
  2157. close;
  2158. end;
  2159. AParam.Free;
  2160. end;
  2161. procedure TTestCursorDBBasics.Testbug7007;
  2162. var
  2163. datalink1: tdatalink;
  2164. datasource1: tdatasource;
  2165. query1: TDataSet;
  2166. begin
  2167. query1:= DBConnector.GetNDataset(6);
  2168. datalink1:= TTestDataLink.create;
  2169. datasource1:= tdatasource.create(nil);
  2170. try
  2171. datalink1.datasource:= datasource1;
  2172. datasource1.dataset:= query1;
  2173. datalink1.datasource:= datasource1;
  2174. DataEvents := '';
  2175. query1.open;
  2176. datalink1.buffercount:= query1.recordcount;
  2177. CheckEquals('deUpdateState:0;',DataEvents);
  2178. CheckEquals(0, datalink1.ActiveRecord);
  2179. CheckEquals(6, datalink1.RecordCount);
  2180. CheckEquals(6, query1.RecordCount);
  2181. CheckEquals(1, query1.RecNo);
  2182. DataEvents := '';
  2183. query1.append;
  2184. CheckEquals('deCheckBrowseMode:0;deUpdateState:0;deDataSetChange:0;DataSetChanged;',DataEvents);
  2185. CheckEquals(5, datalink1.ActiveRecord);
  2186. CheckEquals(6, datalink1.RecordCount);
  2187. CheckEquals(6, query1.RecordCount);
  2188. CheckTrue(query1.RecNo in [0,7]);
  2189. DataEvents := '';
  2190. query1.cancel;
  2191. CheckEquals('deCheckBrowseMode:0;deUpdateState:0;deDataSetChange:0;DataSetChanged;',DataEvents);
  2192. CheckEquals(5, datalink1.ActiveRecord);
  2193. CheckEquals(6, datalink1.RecordCount);
  2194. CheckEquals(6, query1.RecordCount);
  2195. CheckEquals(6, query1.RecNo);
  2196. finally
  2197. datalink1.free;
  2198. datasource1.free;
  2199. end;
  2200. end;
  2201. procedure TTestCursorDBBasics.TestBug6893;
  2202. var
  2203. datalink1: tdatalink;
  2204. datasource1: tdatasource;
  2205. query1: TDataSet;
  2206. begin
  2207. query1:= DBConnector.GetNDataset(25);
  2208. datalink1:= TDataLink.create;
  2209. datasource1:= tdatasource.create(nil);
  2210. try
  2211. datalink1.datasource:= datasource1;
  2212. datasource1.dataset:= query1;
  2213. datalink1.buffercount:= 5;
  2214. query1.active := true;
  2215. query1.MoveBy(20);
  2216. {$ifdef fpc}
  2217. CheckEquals(5, THackDataLink(datalink1).Firstrecord);
  2218. CheckEquals(4, datalink1.ActiveRecord);
  2219. CheckEquals(21, query1.RecNo);
  2220. query1.active := False;
  2221. CheckEquals(0, THackDataLink(datalink1).Firstrecord);
  2222. CheckEquals(0, datalink1.ActiveRecord);
  2223. query1.active := true;
  2224. CheckEquals(0, THackDataLink(datalink1).Firstrecord);
  2225. CheckEquals(0, datalink1.ActiveRecord);
  2226. CheckEquals(1, query1.RecNo);
  2227. {$endif fpc}
  2228. finally
  2229. datalink1.free;
  2230. datasource1.free;
  2231. end;
  2232. end;
  2233. procedure TTestCursorDBBasics.TestNullAtOpen;
  2234. begin
  2235. with dbconnector.getndataset(0) do
  2236. begin
  2237. active:= true;
  2238. CheckTrue(fieldbyname('id').IsNull,'Field isn''t NULL on a just-opened empty dataset');
  2239. append;
  2240. CheckTrue(fieldbyname('id').IsNull,'Field isn''t NULL after append on an empty dataset');
  2241. fieldbyname('id').asinteger:= 123;
  2242. cancel;
  2243. CheckTrue(fieldbyname('id').IsNull,'Field isn''t NULL after cancel');
  2244. end;
  2245. end;
  2246. { TDBBasicsUniDirectionalTestSetup }
  2247. {$ifdef fpc}
  2248. procedure TDBBasicsUniDirectionalTestSetup.OneTimeSetup;
  2249. begin
  2250. inherited OneTimeSetup;
  2251. DBConnector.TestUniDirectional:=true;
  2252. end;
  2253. procedure TDBBasicsUniDirectionalTestSetup.OneTimeTearDown;
  2254. begin
  2255. DBConnector.TestUniDirectional:=false;
  2256. inherited OneTimeTearDown;
  2257. end;
  2258. { TTestBufDatasetDBBasics }
  2259. procedure TTestBufDatasetDBBasics.SetUp;
  2260. begin
  2261. DBConnector.StartTest;
  2262. end;
  2263. procedure TTestBufDatasetDBBasics.TearDown;
  2264. begin
  2265. DBConnector.StopTest;
  2266. end;
  2267. {$endif fpc}
  2268. initialization
  2269. {$ifdef fpc}
  2270. RegisterTestDecorator(TDBBasicsTestSetup, TTestDBBasics);
  2271. RegisterTestDecorator(TDBBasicsTestSetup, TTestCursorDBBasics);
  2272. // The SQL connectors are descendents of bufdataset and therefore benefit from testing:
  2273. if (uppercase(dbconnectorname)='SQL') or (uppercase(dbconnectorname)='BUFDATASET') then
  2274. begin
  2275. RegisterTestDecorator(TDBBasicsTestSetup, TTestBufDatasetDBBasics);
  2276. RegisterTestDecorator(TDBBasicsUniDirectionalTestSetup, TTestUniDirectionalDBBasics);
  2277. end;
  2278. {$else fpc}
  2279. RegisterTest(TTestDBBasics.Suite);
  2280. {$endif fpc}
  2281. end.