Forum > Beginners

[Solved!] Loading checkbox state from SQLite file

(1/1)

heebiejeebies:
Ok so we all saw this topic coming, after my previous one on saving checkbox state....  :D  Really baffled by this one because I've used this exact code before in another test project (only changing the names of the fields and objects), and it worked perfectly.  UserFileLoad is a TSQL query.  Just as a proof of concept I'm getting the data from the query and putting it in a field, tempdisplay2, but in the real world all the data will be true/false so I assume I can read it as a StrToBool and then set each checkbox state accordingly.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---UserFileConnection.Open;UserFileTransaction.Active:= True;UserFileLoad.SQL.Text:=('SELECT * FROM IssueSpecific WHERE _rowid_=:RowParam'); UserFileLoad.Params.ParamByName('RowParam').Value := TempRecordNum.text; UserFileLoad.ExecSQL;UserFileTransaction.Commit; tempdisplay2.Text := UserFileLoad.Fields[1].AsString;    
It compiles, then when I click the appropriate button I get:

Project raised exception class 'EListError' with message:
List index (1) out of bounds

 :(

heebiejeebies:
Tried this as well... this seemed to be the most logical other option:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---tempdisplay2.Text := UserFileLoad.fieldvalues['PRValue']; 
But it doesn't like that either.  Apparently there's no field "PRValue", even though there IS!

And since I loaded the entire table with this, it should be in the query result:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---UserFileLoad.SQL.Text:=('SELECT * FROM IssueSpecific WHERE _rowid_=:RowParam');

paweld:
for SELECT query you must use Open procedure, not ExecSQL:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---UserFileConnection.Open;UserFileTransaction.Active:= True;UserFileLoad.SQL.Text:=('SELECT * FROM IssueSpecific WHERE _rowid_=:RowParam');UserFileLoad.Params.ParamByName('RowParam').Value := TempRecordNum.text;UserFileLoad.Open; // <------ open querytempdisplay2.Text := UserFileLoad.Fields[1].AsString; // or: UserFileLoad.FieldByName('PRValue').AsString; UserFileLoad.Close;

dseligo:
In addition to what paweld said, if there is possibility that your row isn't found, you should check if there is result:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---If not UserFileLoad.Eof then  tempdisplay2.Text := UserFileLoad.Fields[1].AsString // or: UserFileLoad.FieldByName('PRValue').AsString;else  ShowMessage('Row not found.'); 

heebiejeebies:
THANK YOU LEGENDS!!  :D

Could not find anything on this anywhere and thought maybe I was dealing with a corrupted database.

I looked back through the old working code from my test project and, erm, yes.... there it was.... "open" instead of ExecSQL.  It's finicky about where you place the statement in the code, too.... Anyway, it works, brilliant!  That'll keep me busy for another few weeks of coding before I post my next n00b question.  :D

Navigation

[0] Message Index

Go to full version