WebList show zebra

Hello,

I’v got zebra on my WebListBox when I try this code on the opening event of the weblist control when using a loop

// Fill projects list
Var items() As Repository.Project = Repository.Project.All

// Clear
Me.RemoveAllRows

// Works fine
Me.AddRow("Test 1")
Me.AddRow("Test 2")

For i As Integer = 0 To items.Count-1
  Me.AddRow("i " + i.ToString)
Next


// Works fine
Var t As Repository.Project
t = items(0)
Me.AddRow(t.name)

t = items(items.Count-1)
Me.AddRow(t.name)

// Doesn't work
For i As Integer = 0 To items.Count-1
  Var p As Repository.Project
  p = items(i)
  Me.AddRow(p.name)
Next

If I comment the last part of my code, this works fine:

Project is a Class with a single property (name as string). It’s part of Repository Module. And the shared method Repository.Project.All is a simple method to query a mysql Database like this:

Var results() As Project

if Session.db = Nil Then
  MessageBox("Connection to database failed.")
  Return results
End If


Var sql As String
sql = "SELECT * FROM Project"

Var data As RowSet
Try
  data = Session.db.SelectSQL(sql)
Catch e As DatabaseException
  MessageBox("DB Error: " + e.Message)
  Return results
End Try

If data <> Nil Then
  
  For Each row As DatabaseRow In data
    Var item As new Project
    item.name = row.Column("name").StringValue
    results.Add(item)
  Next
  
  data.Close
End If

Return results

Note the same code with db property stored in app works fine in a Desktop Application

Make sure the encodings of the name properties are all set. IIRC everything is converted to UTF-8 before transmission and you could be encountering a conversion exception .

Sorry don’t understand your post. Encoding in MySQL Db is set to UTF8.
Capture d’écran 2025-03-23 à 14.25.02

Something todo in XojoWebApp, On XojoDesktopApp everything’s works fine

Add a breakpoint at the line that does the AddRow and inspect the name parameter in the debugger. It will show the encoding there.

Desktop apps are more forgiving of nil encoded strings than the web is, so unless the string had a NULL character in it, you might not notice.

Everything looks fine and I don’t think of your solution about encoding exception.

This code works fine

// Works fine
Var t As Repository.Project
t = items(0)
Me.AddRow(t.name)

t = items(items.Count-1)
Me.AddRow(t.name)

It’s something about the loop

// Doesn't work
For i As Integer = 0 To items.Count-1
  Var p As Repository.Project
  p = items(i)
  Me.AddRow(p.name)
Next

Create a sample project to share here or open an issue with it and description of the problem.

webapp_test.xojo_binary_project.zip (13.3 KB)

Your project is missing the images.
Your project connects to a MySQL database, but we don’t have a dump for it (we can’t rule out non UTF-8 encoding).

Try to create your sample with the images and use SQLite instead (so there is no need for MySQL connection). I can’t work with MySQL today.

1 Like

db is very simple :

-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: db-edisontv-mysql-do-user-14184544-0.m.db.ondigitalocean.com:25060
-- Generation Time: Mar 23, 2025 at 02:36 PM
-- Server version: 8.0.35
-- PHP Version: 8.3.14

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `edisontv`
--

-- --------------------------------------------------------

--
-- Table structure for table `employee`
--

CREATE TABLE `employee` (
  `id` int NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Table structure for table `project`
--

CREATE TABLE `project` (
  `id` int NOT NULL,
  `parent_id` int DEFAULT NULL,
  `name` varchar(128) NOT NULL DEFAULT 'new project',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `project`
--

INSERT INTO `project` (`id`, `parent_id`, `name`, `created_at`, `updated_at`) VALUES
(1, NULL, 'DCM', '2025-03-23 07:53:00', '2025-03-23 14:24:25'),
(2, 1, 'DCM S89', '2025-03-23 07:53:48', '2025-03-23 08:06:24'),
(3, 1, 'DCM S90', '2025-03-23 07:53:48', '2025-03-23 08:06:42'),
(4, 1, 'DCM S91', '2025-03-23 07:55:48', '2025-03-23 08:06:49'),
(5, 1, 'DCM S92', '2025-03-23 07:55:48', '2025-03-23 08:06:56'),
(6, 1, 'DCM S93', '2025-03-23 07:56:17', '2025-03-23 08:07:06'),
(7, 1, 'DCM S94', '2025-03-23 07:56:17', '2025-03-23 08:07:15'),
(8, 1, 'DCM S95', '2025-03-23 07:56:52', '2025-03-23 08:07:21'),
(9, 1, 'DCM S96', '2025-03-23 07:56:52', '2025-03-23 08:07:28'),
(10, 2, 'DCM S89 Prépa', '2025-03-23 08:06:10', '2025-03-23 08:06:10'),
(11, 2, 'DCM S89 DA', '2025-03-23 08:06:10', '2025-03-23 08:06:10'),
(12, 1, 'DCM S90 Prépa', '2025-03-23 14:24:13', '2025-03-23 14:24:13');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `employee`
--
ALTER TABLE `employee`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `project`
--
ALTER TABLE `project`
  ADD PRIMARY KEY (`id`),
  ADD KEY `parent_id` (`parent_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `employee`
--
ALTER TABLE `employee`
  MODIFY `id` int NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `project`
--
ALTER TABLE `project`
  MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=13;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `project`
--
ALTER TABLE `project`
  ADD CONSTRAINT `parent_id` FOREIGN KEY (`parent_id`) REFERENCES `project` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Can you explain why only the code in a loop doesn’t work? What is the link between encoding and ForEach loop?

Go back to that debugger and click on the little pencil icon on the right. In there it’ll tell you what the encoding of the string is in a popup menu.

1 Like

UTF8

Try editing your code to force UTF8 on all strings pulled from the database:

Repository.Project.All as String()
[...]
For Each row As DatabaseRow In data
  Var item As new Project
  var s as string = row.Column("name").StringValue
  s = s.DefineEncoding(encodings.UTF8)  <-- Add this line
  item.name = s
  results.Add(item)
Next

I try your solution but nothing change. On more why do you thing it’s something about encoding? This code works in the same project. It’s adding the first and last project from Repository.Project.All as Project()

I can’t reproduce your bug since I don’t have your database. .

I did just try extracting your strings and storing them as a string constant in the Xojo project, and then it works fine:

Here’s something I don’t understand.

You say this works fine:

Var t As Repository.Project
t = items(0)
Me.AddRow(t.name)

t = items(items.Count-1)
Me.AddRow(t.name)t = items(items.Count-1)
Me.AddRow(t.name)

Your list has 12 items, starting with “DCM” and ending with “DCM S90 Prépa”

However in your screenshot above, you only have 11 items ( from “i 09” through “i 10”) and you also show “12 coups de midi” (which I don’t see anywhere) and “DCM S89 DA” which appears to be the 11th (not 12th) item in the list. Something seems off. Are you sure the code and SQL dump you uploaded is the actual code you are using?

I thought you were talking about a printer :rofl:.

This morning I found major int for solution some project name have “é”. If I remove this characters everything works fine. You are all right it’s something about encoding.

I need more help. My database collation is set to: utf8mb4_0900_ai_ci
Maybe I need to apply another encoding in my database?

Here the solution I found:

  • define encoding (from mysql collation)
  • convert encoding (for web app)
Var sql As String
sql = "SELECT * FROM project"

Var data As RowSet
Try
  data = Session.db.SelectSQL(sql)
Catch e As DatabaseException
  MessageBox("DB Error: " + e.Message)
  Return results
End Try

If data <> Nil Then
  
  For Each row As DatabaseRow In data
    Var item As new Project
    item.name = row.Column("name").StringValue.DefineEncoding(Encodings.ISOLatin1).ConvertEncoding(Encodings.UTF8)
    results.Add(item)
  Next
  
  data.Close
End If
1 Like

Great! But this seems like a bug that we should report. Can you make a sample project that is self contained?

He probably doesn’t need the ConvertEncoding part, but certainly if it had a Nil encoding, the framework would have no way to recover.

Personally I don’t think this is a bug. Having your strings properly encoded when they come from an external source is your responsibility and if you decide not to do anything, the result is also undefined.

1 Like