simonkrauter/NiGui

Looping through SQLite and adding Labels with Results

wwderw opened this issue · 10 comments

I am trying to loop through a database. Just for an example I have:

for x in db.fastRows(sql("SELECT Name FROM SQLite_master ORDER BY 1 ASC")):
for seriesName in x:
#echo seriesName
var label = newLabel($seriesName)
mainContainer.add(label)

Now, I echo the results in the first loop or the second loop (I do have the appropriate open() and close() for the db), I get what I would expect:

@["series"] in the first loop or just the series name in the second loop in the terminal.

However, with the above code, it just locks up the program. Almost as if it's in an endless loop, but the table should terminate. It terminates appropriately when I just use the echo command.

I just dunno. Thoughts of where to look? I did look in the examples of the looping of the buttons and that's what I tried to emulate for just labels.

Creating widgets in a loop should work.
Please show a minimal program to reproduce and what OS you use.

Below is attached a portion of the nim code. OS is Ubuntu Studio 21.04. I also tried this in a Linux Mint VM (same database, same version of NiGUI and NIM) and it actually wouldn't compile. It told me that there was an error with ComboBoxChangeEvent.

example.txt

I modified the program to this:

import nigui

app.init()

#Adding Main Window and Main Layout
var window = newWindow("programName")
var mainContainer = newLayoutContainer(Layout_Vertical)
window.add(mainContainer)

#Menu Layout
var menu = newLayoutContainer(Layout_Horizontal)
mainContainer.add(menu)

#Menu Options

var filesMenu = newComboBox(@["Files", "Get Master Log"])
filesMenu.width = 200
menu.add(filesMenu)

filesMenu.onChange = proc(event: ComboBoxChangeEvent) =
    if filesMenu.value == "Get Master Log":
       for seriesName in ["1", "2", "3"]:
          #echo seriesName
          var label = newLabel(seriesName)
          mainContainer.add(label)

    filesMenu.value = "Files"

window.show()
app.run()

After setting the combobox:
Screenshot

I can't imagine the reason for your problem.

Something with the fact of going thru SQLite maybe? That's really the only difference that I can think of between your version and mine.

I was able to do the example of the buttons just fine on my host OS (again Mint didn't like the ComboBoxChangeEvent at compile time).

Edit: I fired up the VM for Mint to get the exact error and it is:
Error: undeclared identifier: "ComboBoxChangeEvent"

Again, that is only trying it in Linux Mint. Compiles fine in Studio, just tends to freeze.

I spun up my Win 8.1 VM and it froze with that one as well. I'm not getting any terminal errors to try to troubleshoot.

I tried it with a SQLite database file and it works.

About

Error: undeclared identifier: "ComboBoxChangeEvent"

Try the head revision of the repository of NiGui.

That is strange. Is my code fundamentally wrong some where? Anything that I would need to check on Studio since its Plasma based, maybe the GTK version is not up to snuff or something?

What do you mean by head revision? I have been using the Master branch (i manually download, CD into root directory them do nimble install).

Ok, with sqlite. It turns out that the program is looping thru slowly with the sql query. I let the program run and roughly 6 minutes later, everything populated.

I don't know why echoing the results is almost instantaneous, but it seems to be moving much slower otherwise. Now the table I am retrieving is not small, ~2100 entries, but it does seem strange for it to take roughly 6 minutes to loop thru. Looking in the Nim documentation, fastRows is indeed what I should be using. I just don't know, but that is a lot of a performance hit.

Number number of ~2100 entries explains why it does not work (or is very slow). Since every widget has an overhead, this won't work. In future it should work with a TableView widget.

That makes sense. Thanks for the help.