[solved] endless loop - I feel stupid lazarus / 16-Databases ---------------------------------------------------------------------- Nicole · 2024-02-24 09:41 This is a question I feel very stupid to put it. I have an endless loop. Since 2 days I simplify it and cannot see, why: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   ShowMessage('before');   IBSQLChart.Active:=true; // I tried both IBSQL and IBquery, so before here was ExecQuery with the same effect  while not IBSQLChart.Eof do begin   {  *simplified = set into brackets*              }     IBSQLChart.Next;  end;  ShowMessage('after'); ---------------------------------------------------------------------- domasz · 2024-02-24 10:07 Quote from: Nicole on February 24, 2024, 10:41:39 am Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   ShowMessage('before');;Ah, Grandma's debugger, classic! ---------------------------------------------------------------------- Joanna · 2024-02-24 13:25 I’m not familiar with ibsqlchart but I’m curious what happens if you insert ibsqlchart.First;  After line 3? Also is there any way to trace into the code in loop to find out what it is doing? ---------------------------------------------------------------------- rvk · 2024-02-24 13:41 WHAT is IBSQLChart at the moment?? If it's a TIBQuery or TIBSQL then there is something in your code which you commented out. Did you try to put that code in comments and see if it's still loops endlessly??? TDataset.First after setting TDataset.Active to true shouldn't make a difference because it's always at the first record after opening. That is... IF the TDataset wasn't already active before that line !!! And that's a big if because we don't see any other code (as usual). Just try the code exactly as you put it here in your post and report back. If it's still happening... show us more code from before this code. ---------------------------------------------------------------------- Nicole · 2024-02-24 17:03 Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i WHAT is IBSQLChart at the moment??If it's a TIBQuery or TIBSQL then there is something in your code which you commented out. TIBQuery Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Did you try to put that code in comments and see if it's still loops endlessly??? yes!! Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TDataset.First after setting TDataset.Active to true shouldn't make a difference because it's always at the first record after opening. That is... IF the TDataset wasn't already active before that line !!!And that's a big if because we don't see any other code (as usual). Just try the code exactly as you put it here in your post and report back.If it's still happening... show us more code from before this code. To make sure, I had added the line Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i IBSQLChart.Active:=false;already. Is it good style to set the query to active? Or shall I switch something else? Where the trouble occurs is at the end of looping. I watched the first datasets passing through and watched the "order by" criteria. It runs about to the end. So to my mind the problem is the .EOF, which is not triggered. ---------------------------------------------------------------------- rvk · 2024-02-24 17:18 Quote from: Nicole on February 24, 2024, 06:03:10 pmWhere the trouble occurs is at the end of looping. I watched the first datasets passing through and watched the "order by" criteria. It runs about to the end. So to my mind the problem is the .EOF, which is not triggered. If you don't do anything other than .Next inside the loop then the EOF should trigger. That's why I asked if you commented everything out like you showed. If it still doesn't work then it must be a bug and you need to report it. (But I still find it very strange that this can happen.) Does it happen with all your tables? BTW. It could also be a corruption on your database/index. What happens with the same query in Flamerobin and you choose fetch all? .Active := true should be the same as .Open. https://www.freepascal.org/docs-html/fcl/db/tdataset.active.html ---------------------------------------------------------------------- Nicole · 2024-02-24 18:28 yes and yes and yes and it works in Flamrobin,.................. BUT it took 16 seconds for listing 58 data with 3 fields each So there shall be something wrong with the table. This is what the statisics of FlameRobin say. and 27726511 fetches?! should be about 100 Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Starting transaction...Preparing statement: select datum, betrag, fk_einkommen from tbkupons order by fk_einkommenStatement prepared (elapsed time: 0.001s).Field #01: TBKUPONS.DATUM Alias:DATUM Type:DATEField #02: TBKUPONS.BETRAG Alias:BETRAG Type:NUMERIC(18,2)Field #03: TBKUPONS.FK_EINKOMMEN Alias:FK_EINKOMMEN Type:INTEGERPLAN (TBKUPONS ORDER FK_TBKUPONS_0)Parameters: 0  Executing statement...Statement executed (elapsed time: 0.000s).27726511 fetches, 2 marks, 911 reads, 0 writes.0 inserts, 0 updates, 0 deletes, 103 index, 25072676 seq.Delta memory: 101168 bytes.RDB$PAGES: 25072675 reads sequence. RDB$DATABASE: 1 reads sequence. RDB$FIELDS: 4 reads index. RDB$INDICES: 6 reads index. RDB$RELATION_FIELDS: 8 reads index. RDB$RELATIONS: 4 reads index. RDB$FORMATS: 1 reads index. RDB$SECURITY_CLASSES: 2 reads index. RDB$TRIGGERS: 1 reads index. TBKUPONS: 77 reads index. Total execution time: 16.781sScript execution finished. I tend to delete all data and re-write them including reset the index. The more I think about it, the more strange things come up to my mind. E.g. that the index was expected to be about 30 and it was 18.000. Perhaps I made a mistake in writing the id's generator. I did not do do this too often in my life. If anybody guesses better than me what went wrong, I would be grateful, if he shares it. PS: I bet, you want to see it: generator QuoteCREATE SEQUENCE GEN_TBKUPONS_ID START WITH 1 INCREMENT BY 1; trigger QuoteSET TERM ^ ; CREATE TRIGGER GEN_TBKUPONS_TR FOR TBKUPONS ACTIVE BEFORE insert POSITION 0 as begin   if (new.id_kupon is null) then     new.id_kupon = gen_id(GEN_TBKUPONS_ID,1); end ^ SET TERM ; ^ ---------------------------------------------------------------------- rvk · 2024-02-24 18:48 Quote from: Nicole on February 24, 2024, 07:28:39 pmIf anybody guesses better than me what went wrong, I would be grateful, if he shares it. PS: I bet, you want to see it: No, we need to see your SQL and the database DDL (with indexes etc). ---------------------------------------------------------------------- egsuh · 2024-02-25 04:19 try something like following: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   IBSQLChart.Active:=true;   ibsqlchart.first;  while not IBSQLChart.Eof do begin     memo1.lines.add (ibsqlchart.fields[0].asstring);    {  *simplified = set into brackets*              }     IBSQLChart.Next;  end;   Memo1.lines.add('Loop finished'); First, simply run this codes. If you see the finial text, then there are no problem with next--- eof.  If the application is down after showing the last record then there should be some problem with next--- eof logic. Else, there would be a problem in your codes which have been commented out. ---------------------------------------------------------------------- Nicole · 2024-02-28 10:10 Thank you for all answers. Probably the problem never had been an endless loop. May be the query led to an extreme high traffic in answers, which lasted that long, that it felt like an endless loop. WHY this answers were that long / verbose / plenty, - no idea. It was a new table with a handful of records. It should not feel any delay. However I found the whole database suddenly damaged: a few triggers and constraints were gone. So I saved the DDL and just dropped the whole table and wrote it new as table and its content. Now the looping query works without noticeable delay. To sum up: The problem was the database. The solution brought the idea, to try the query in FlameRobin, there I discovered the db-problem. ---------------------------------------------------------------------- rvk · 2024-02-28 10:13 Quote from: Nicole on February 28, 2024, 11:10:35 amWHY this answers were that long / verbose / plenty, - no idea. It was a new table with a handful of records. It should not feel any delay. However I found the whole database suddenly damaged: a few triggers and constraints were gone.Yeah, and that can definitely lead to slowness of your queries. Quote from: Nicole on February 28, 2024, 11:10:35 amSo I saved the DDL and just dropped the whole table and wrote it new as table and its content. Now the looping query works without noticeable delay.Which will not fix your original problem as to WHY the database got corrupted. You should really keep an eye on that. (check backups and S.M.A.R.T. of your harddisk regularly.) ---------------------------------------------------------------------- dseligo · 2024-02-28 12:11 Quote from: rvk on February 28, 2024, 11:13:56 amQuote from: Nicole on February 28, 2024, 11:10:35 amSo I saved the DDL and just dropped the whole table and wrote it new as table and its content. Now the looping query works without noticeable delay.Which will not fix your original problem as to WHY the database got corrupted. I agree. There is no point of correcting data and DDL if root cause is not identified and solved. ---------------------------------------------------------------------- Nicole · 2024-02-28 14:14 In the meanwhile I suspect, that a tool may have damage something, which cleaned up the virtual disk. It is from VMWare and says "clean up no more needed but reserved space of your virtual HD" or similar. This would explain, why elements of the database were gone, which I was sure, to have been there.