Event Loop Issue When Populating a Listbox with MariaDB Data

Hello everyone,

I’m working on a Xojo Web application that previously used SQLite and has now been migrated to MariaDB. Since the migration, I’ve encountered an issue: When populating a Listbox, an Event Loop error occurs, causing the application to freeze.
What happens?

The database connection works (login and other queries execute successfully).

The SQL query returns valid data.

However, the Listbox is not updated correctly – sometimes values are missing, or no rows are displayed.

Shortly after entering the While Not rs.AfterLastRow loop, the app freezes, and the debugger only shows “Event Loop.”

To rule out any interference with the login process, I have now moved this method out of the login flow and instead trigger it manually via a button click to ensure all previous processes have completed – but the issue persists.

My code for populating the Listbox:

Var rs As RowSet = db.SelectSQL(“SELECT name FROM users WHERE active = 1”)

If rs = Nil Then
System.DebugLog(“Error: RowSet is Nil!”)
Return
End If

While Not rs.AfterLastRow
System.DebugLog("Row Data: " + rs.Column(“name”).StringValue) // Debug output works!
Listbox1.AddRow(rs.Column(“name”).StringValue)
rs.MoveToNextRow
Wend

What I have tried so far:

Checked the SQL query → The data appears correctly in Navicat.

Verified whether the RowSet is nil or empty → The RowSet is valid and contains data.

Added debug output before updating the Listbox → The values are correctly retrieved from the database.

Limited the loop iteration (count < 10) → No difference, the problem persists.
Tried adding all rows after the loop instead of inside it → No improvement.
Checked rs.MoveToNextRow behavior → Looks normal, but could this be causing the issue?
Moved the method out of the login process → It is now triggered by a button click, but the problem remains.

Questions:

Has anyone experienced similar issues with Xojo Web 2.0 and MariaDB?
Are there known issues with rs.MoveToNextRow or Listbox.AddRow in Xojo Web?
Could this be related to a UI thread problem? (I am not explicitly using any threads)

I appreciate any help or suggestions!
Best regards,

When the debugger pauses with no information inside a class prefixed with an underscore, it’s a runtime exception in the Xojo code side of the framework.

There’s nothing you can do, you can’t even catch these. You’ll have to file a ticket with a reproducible sample so that the framework can be fixed.

2 Likes

Yes, could you please open a new issue and attach a sample project so I can check what’s going on?

You can create a confidential case, if you cannot make a standalone sample project and prefer to send a bigger one.

1 Like

You could at least try to see if that’s a possible issue.

For that I’d rule out that you’re certainly not adding some “invalid chars” (which might lead to an Issue with Listbox1.AddRow), e.g. by changing:

from: Listbox1.AddRow(rs.Column("name").StringValue)
to: Listbox1.AddRow(EncodeBase64(rs.Column("name").StringValue))

1 Like

I did that and it worked. So that means i have an issue with my database?

Well, not with the Database itself.

But it seems that at least one of the rs.Column("name").StringValue’ contains some (hidden / invalid) character, which doesn’t seem to play nice with WebListbox.

Would be interesting to know which character it is that messes up the WebListbox

Try this: an break the lines yourself in the debugger so that you can see the encoding (probably nil)

Var rs As RowSet = db.SelectSQL(“SELECT name FROM users WHERE active = 1”)

If rs = Nil Then
System.DebugLog(“Error: RowSet is Nil!”)
Return
End If

While Not rs.AfterLastRow

Var name As String = rs.Column(“name”).StringValue // <-- break here, then step and see the value encoding
System.DebugLog("Row Data: " + name) // Debug output works!

Listbox1.AddRow(name)

rs.MoveToNextRow
Wend

Defining the encoding and then converting it to UTF8 (if needed) should work fine in that case.

I had to set this after the db.connect

db.SQLExecute(“SET NAMES ‘utf8mb4’;”)
db.SQLExecute(“SET CHARACTER SET ‘utf8mb4’;”)

2 Likes

Yup, certainly a good idea to define the character set for the DB connection :wink:

Still I’m wondering if WebListbox should/could handle this better… what does @Ricardo_Cruz think?

I think we can raise an exception if there is no encoding, or if it’s incompatible (I think it might fail if it isn’t encoded in UTF-8)

Or at least throw the exception when there is no encoding defined, and try to convert it to UTF-8 internally.

It would be preferable for the MySQL plugin to encode the StringValue with the encoding of the table or database.

Some time ago this “you have to define the encoding on all database results” was introduced and since it hasn’t personally affected Geoff, we’re still dealing with this mess and we really shouldn’t have to be.

1 Like

Is there any case regarding the Database encoding created already?

Still, the control could do a better job at complaining when trying to feed it with data that it won’t support.

1 Like

Probably, but my patience with that system had been exhausted.

Quite agreeable, and why I discuss issues with you directly.

1 Like

How about that 14 year old issue: Issue 14166: Database class should have an Encoding property / handling

1 Like

In electronic, when you enconter stange behaviors, blame the power supply.

In Web app, when you enconter stange behaviors, blame the encoding.

Have the database class add a DefaultEncoding property that can be set to a encoding that will be used when returning StringValue only when no valid encoding is set.

Property so that it can be reset to Nil when you need a nil based string.

@Ricardo_Cruz

1 Like