Xojo2024R2: how to obtain comma separated values from WebListBoxRowData?

Assuming I have vRowData as WebListBoxRowData that has columns such as “m_code” and “c_code” with values “AXI” and “BNY”.

I want to obtain “AXI,BNY”.

I could use
vValue = vRowData.Value(“m_code”) + “,” + vRowData.Value(“c_code”)

For generic solution, is there a way to obtain the list of column values without specifying column names in the row and not using loop?

If you have all values in an array, you can do:

dim values as string = String.FromArray(myArray, “;”)

Well, this code:

vColumnNameStr = String.FromArray(vColumnNameArray,",")

is giving me the comma separated list of column names from my vColumnNameArray.
However, I need the comma operated list of values from the vRowData

Var vRowData As WebListBoxRowData

note:
I can see PrimaryKey and Tag
Screenshot 2024-07-05 at 12.54.13 PM

I was hoping that there is a one liner like this that could do the trick:

vValue = vRowData.Value(vColumnNameStr)

but it is not working of course.

What is the Problem of:

Dim csv() as string
For i as integer = 0 to lb.Columncount -1
csv.add(lb.celltextat(row, i)
next

Well, in my case the WebListBox is using DataSource (Postgres database), so certain methods are not available compared to regular WebListBox. Then also I was hoping to minimize the looping as this is part of data export, large data sets.

Well, thanks for the tip, but here is the a little info on what I am doing.

  1. User runs Report and builds list on the web page (picks any report from the list and fills in some parameters if needed).
  2. The data is presented in the WebListBox (the layout of the list control is changed dynamically depending on the Report selected).
  3. The list is using DataSource because there may be large data set returned from database for the underlying query.
  4. Once on the screen user may export data from the list as in the list (meaning preserving column layout and sorting).
    Note:
    there could be more to it, user could remove certain lines, do some sorting (btw, it would be nice if WebListBox could support nice multi sorting UI)

So this is not for me to export data from the database (as you suspect I could do it in my sleep - joking but almost true). This has to be part of the web app.

This works but I was hoping to make it a little better. I am sure there is a better way to do it.

Anyway, I will most likely move this method to the underlying data source (ex: QueryPageDataSource1.ExportData).

You said “large Datasets”, in that case I would never, ever do it this way.
If the user could change things like column order or sorting, you could easily do a “new” query to the database with with this way, the user changed it. From that it is easy to do an export as csv.

just use the same query you used to search in the webdatasource to export the postgres database using the query in my link above

Your File is completely built in memory, I have a little difficulty reconciling this with “large dataset” and a multi-user system :wink: You should use a Binary-Stream and write it line by line.

But, of course, you should let the DB do that.
You have the (changed by user) order of columns, you know which column the table ist sorted und you can save all Ids of user deleted rows in an array.
So it is very easy to write a select statement that reflects all this

OK, will it work with web app? The database server is somewhere “out in the bush”.

How would the server “know” where to put the file on the local machine?

Can you give me an example?
Please understand, I have inherited Xojo2018 web app a year ago (never heard of Xojo before).

You can open a fileshare on the Webserver and connect the db-system to there. Or use a third party share, cloud etc. Or you could have a worker on the db-system, that copies the file with scp, or mails it to the user, or ,or ,or…

Keep in mind please, people are using VPN, two way authentication, they are not allowed to install anything on their machines without approval, the web server runs elsewhere and needs to be secure - having said the above, I have no way of changing anything on any machine.

Yes, shure. But I don’t know for what. You said, the user could change the Columns and Sorting.
So, you should know, the columns, in the moment, when the user starts the download.

So you can create a new Select string like “SELECT fieldd, fieldb, fieldt, fieldm FROM …”
instead of “SELECT * FROM”

You know the Column, the user sorted the table, so you can use something like: “… ORDER BY fieldy

And you can put deleted rows (db-id-column-values) and use a where like:

“WHERE NOT id IN (1, 5, 7, 9, 1486)”

yes you can query a postgres database from a xojo web application
use a webfile.download method to download any file to the client browser

https://documentation.xojo.com/api/web/webfile.html#webfile-download

You are writing Code, this WebApp has to be installed somewhere. So not changing anything on any machine is a way, you can change nothing.

The WebListBox with DataSource in Xojo2024R2 is supposed to pull the data as needed from the server as you scroll - be it 10 rows or 150,000 rows. The rendered control does not have all data, there is not bound list variable that would hold it (in Xojo2018 version we have bound list variable that holds the data and of course this is not suitable for the large data sets).

I was hoping that you can give me an example of how to implement export data routine using WebListBox with DataSource.

In my code I use query with LIMIT/OFFSET clause to pull data in batches but as you have correctly noticed everything is concatenated into memory variable, then written into the text file.

If you can suggest a different way of using LIMIT/OFFSET and export into the file please let me know using Xojo2024R2. Thanks.

Jean-Yves, the export data work and is downloaded to the client, that is not the problem.
I am just trying to figure out the way to deal with larger data sets.

If I understand you correctly, the one way to do it would be:

  1. Web app telling Postgress server to export data and place it onto the shared location on the web server.
  2. Download produced file from the web server into the local machine directory.

This sounds very easy but there are few issues.

  • user needs to have permissions to execute the query exporting data on Postgress database server
  • Postgress database server have permission to put the file onto shared directory available to web server
  • client knowing when the file is ready for download

This is not as easy as it sounds I am afraid. I will explore this approach though, thanks.

Btw, my original question was how to get the comma separated list of values from the data row without doing it in the loop and knowing column names, preferably as “one liner”.