[SOLVED] TSQLQuery SQLite EOF issues lazarus / 16-Databases ---------------------------------------------------------------------- yoctobit · 2020-08-31 09:07 Hello all, eventually had the need to sign up for the forum to ask questions so as a short introduction: i've been programming Object Pascal since Delphi1 and the last decade or so using FPC/Lazarus. I'm not the greatest programmer, it's also a hobby and at work it's part of what i do, we make electronic measurement equipment. I've ran into an issue with TSQLQuery connected to a SQLite database. I use the typical 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 while not (Q.EOF) do begin ... ; Q.Next; end;construction. It appeared on my dataset this only works correcly if i add a LIMIT to the query, f.e.: 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 'SELECT stamp,%s FROM `%s` WHERE TRUE %s ORDER BY stamp ASC LIMIT 15000' However, if i remove the limit, or make the number bigger - it's likely the same issue - the query partly fails. It will return the first thousand or so records, then suddenly report EOF. If i limit to 15000 records, i get the complete data set. I do a First and a Last already, as suggested in https://forum.lazarus.freepascal.org/index.php/topic,48738.0.html , since i need the timestamps to scale stuff into a graph. So going by the docs and other topics the complete dataset should already be buffered. It obviously is not or better said: it lost data. After doing .last the last record actually contains valid data, but i cannot loop the whole data set for some reason. What am i overlooking? Or did i bump into so bug, like memory limitations? Records are not insanely large, just numeric data. Any workaround? ---------------------------------------------------------------------- rvk · 2020-08-31 09:15 Quote from: yoctobit on August 31, 2020, 11:07:13 amIt appeared on my dataset this only works correcly if i add a LIMIT to the query, f.e.: 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 'SELECT stamp,%s FROM `%s` WHERE TRUE %s ORDER BY stamp ASC LIMIT 15000'TRUE %s ??? What do you provide as the three %s'es? Maybe you can show the exact loop-code. (exact code, not just snippets) ---------------------------------------------------------------------- yoctobit · 2020-08-31 09:22 I'm sorry, the statement gets formatted like 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 Format ('SELECT stamp,%s FROM `%s` WHERE TRUE %s ORDER BY stamp ASC', [..]) The actual query looks like 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 SELECT stamp,* FROM `1C12` WHERE TRUE AND stamp>0 ORDER BY stamp ASC And the loop+query init code: 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   Q.SQL.Text:=filteredQuery;   Q.Open;  Q.First;  pstart := Q.FieldByName('unixstamp').AsLargeInt;  Q.Last;  pend := Q.FieldByName('unixstamp').AsLargeInt;  Q.First;   //set the desired range  SetPlotRange (pstart, pend);   //clear our existing graph  ClearPlot;   while not Q.EOF do begin    for i:=1 to Q.FieldCount-1 do begin      if Q.Fields[i].IsNull then continue;      Plot (Q.FieldDefs.Items[i].Name, Q.Fields[i].AsFloat, Q.FieldByName('unixstamp').AsLargeInt);    end;    Q.Next;  end;      Where Q is type TSQLQuery. ---------------------------------------------------------------------- rvk · 2020-08-31 10:04 Quote from: yoctobit on August 31, 2020, 11:22:45 amAnd the loop+query init code: From your code I see no reason why a "LIMIT 15000" would give you the complete set and without the limit you don't get everything. ---------------------------------------------------------------------- yoctobit · 2020-08-31 12:34 I'm sorry to have opened the topic  - it was bothering me since last week and i couldn't pinpoint the issue. The problem is not with fetching the data. Listed code is working properly. The error was outside the code (and i did not find it yet) but had mislead me. After double-checking i can tell that all records are fetched just fine... Can i delete the topic as it's no longer relevant to others? --in case anyone wonders: at the end of the dataset was a record with a datestamp that had suddenly jumped a few year because someone who's name shall not be mentioned adjusted the HW clock during equipment testing. While visualizing, by jumping several years without data it appeared as the dataset was only 10% filled. You can all laugh at me now ---------------------------------------------------------------------- rvk · 2020-08-31 12:45 Quote from: yoctobit on August 31, 2020, 02:34:35 pmThe error was outside the code (and i did not find it yet) but had mislead me.Isn't it always  Quote from: yoctobit on August 31, 2020, 02:34:35 pmCan i delete the topic as it's no longer relevant to others? Not sure if you can delete topics. You could edit the starting post and put [SOLVED] in front of the subject.