Get field content without

Hi, this is my first day here.
I switched from LiveCode and got stuck when trying to get the contents of the fields related to the same ID of two different columns in a sqlite-database without using a ListBox as I did before.

Is there any way to open the db,
SELECT german, english FROM dictionary WHERE ID = X
and directly get one string containing the entry in both fields with ID X in the columns “german” and “english” from the rowset?

Thank you for helping.

Just use CONCAT() like in the following example:

SELECT CONCAT(german, " - ", english) FROM dictionary WHERE ID = X

This would result in a string like: “der - the”.

Source: MySQL CONCAT() Function

Try:
SELECT german || ’ - ’ || english FROM dictionary WHERE ID = X

Thanks. But then, how can I open the resulting rowset as a string?

rowsfound = db.SelectSQL(sql)

https://documentation.xojo.com/api/databases/sqlitedatabase.html
https://documentation.xojo.com/topics/databases/supported_engines/sqlite/sqlite_basics.html

Thanks. I’ll work this (2nd link) through, haven’t seen it yet.

1 Like

And the examples in the Xojo Folder might be helpful as well.

strTranslation = rowsfound.ColumnAt(0).StringValue

By standard, you should avoid to access Columns by ID, because it makes errors likely if you change something later. You can do the following for example:

SELECT CONCAT(german, " - ", english) As theResult FROM dictionary WHERE ID = X

and then:

strTranslation = rowsfound.Column("theResult").StringValue

1 Like

Perfect! I was looking for something similar to your solution:
CONCAT and strTranslation = rowsfound.Columnat(1).StringValue

Would be even more convenient if one could use RowsFound.ColumnAt(1,2,4,6…).StringValue without CONCAT (like in LiveCode) allowing handling the result as an array, but I am fine with this.

Helps me a lot going on. Thanks again.

1 Like

Can you please mark this Thread as solved (by selecting a post as solution) ? Thank you :slight_smile: