Forum > Database

[Solved] Dumb SQLite question asked by an idiot

(1/1)

heebiejeebies:
Hi all,

Just fixed the previous bug with the DBLookupListBox, now another bizarre one has appeared. Like the last one, I haven’t changed any of my code and this had been working for 2 years prior to upgrading Free Pascal/Lazarus version. I can’t see how fixing the last error could have affected it.

Anyway, this SQLite query:


--- 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.Open;UserFileLoad.SQL.Text:=('SELECT * FROM MasterProtocol WHERE _rowid_ = :RowParam');UserFileLoad.Params.ParamByName('RowParam').Value := IssueIndex;      if UserFileLoad.Fieldbyname('Workspace').AsString = 'True' then WorkspaceCheckbox.Checked:= true;       
Now complains that the field Workspace doesn’t exist. I’ve added some debugging checks just before the code is executed, which confirm the following regarding UserFileLoad:

The database name is correct;
The query is correct;
The query is opened without error;
RowParam returns a valid record ID;
The query returns all the correct fields;
The dataset is active /1 record returned; and
Correct data is read from the fields!

My code above appears directly after the end of the successful checks; there’s nothing else in between the checks and the above.  Yet the checks work and the above code fails due to missing field.

Strangest one I’ve ever seen I think?! Where do I even start?

dsiders:
Why are you opening the dataset before setting the SQL and parameter values?

heebiejeebies:
Haha, because I'm a moron, clearly. I was so hung up on why this worked previously that I didn't even notice that.

Seriously though, WHY DID THIS WORK PREVIOUSLY??!!? I didn't change ANYTHING in the code. I wonder if it's something to do with the changes to the sqlite3connection class.

dsiders:

--- Quote from: heebiejeebies on December 13, 2024, 10:04:26 pm ---Haha, because I'm a moron, clearly. I was so hung up on why this worked previously that I didn't even notice that.

Seriously though, WHY DID THIS WORK PREVIOUSLY??!!? I didn't change ANYTHING in the code. I wonder if it's something to do with the changes to the sqlite3connection class.

--- End quote ---

I don't know, but we can't debug your code without having your code. But I will add that 'SELECT * FROM' is bad idea. Use an explicit column selection List. The design-time editors with even do it for you.

Zvoni:

--- Quote from: dsiders on December 14, 2024, 12:44:26 am ---But I will add that 'SELECT * FROM' is bad idea.

--- End quote ---
Another bad idea in SQLite is to filter on rowid.
Use an explicit PrimaryKey-Column

EDIT: And don't use "Value" on the Params (Line 3). Use explicit DataType... "AsInteger"

Navigation

[0] Message Index

Go to full version