Eval or similar methodology?

I have several connection strings in an app with a variable called vSchema which holds values such as “xyz”.
I need to concatenate a statement to produce the results:

rs = App.xyz.SQLSelect(SQL_Select)

In another tool i would do something like this:

rs = eval(“App.” + vSchema + “.SQLSelect(SQL_Select)”)

and that would work.

How do i do that in Xojo?

You cannot access an object via a concatenated string.

This might work in an Interpreter or some Pcode compilers

Your “best” option is to use Introspection to search the target object for a matching method or property, then invoking. It’s not necessarily simple, but it’s possible. Otherwise, you’d have to use a Select Case statement and code-in every possible xyz value.

Yeah, I was using Select Case which really sucks. I don’t know anything about introspection, so…

You have the right to mention the other tool. It would be a lot clearer.

From what I read about eval in VBScript, it is only possible because VBScript is not a compiled language.

Perhaps XojoScript would have the equivalent, but I hardly ever used it, so someone else may be better suited to tell.

Alpha Anywhere is the tool, xbasic is the language. Yeah, xbasic is an interpreted language. Of course, eval() lives in JavaScript too, which also is interpreted.

may be you could try this example and adapt it to your needs.

Thanks Jean, I’ll take a look and see what I get out of that.

Examples/Advanced/XojoScript/Evaluator looks interesting.

Are those different schemas for the same database (e.g. PostgreSQL) or even different schemas in different databases (e.g. some in MySQL and some SQLite)? Whatever you are thinking, maybe there’s a functional “another way” of doing it. Something like:

rs = MultiDBSelect(theDB, theSchema, theSelect)

In your function code you can select the proper Database connection, use it to send an “USE theSchema” command (or “SET search_path TO theSchema,public;” for Postgresql; or another proper way to another one), and then query and return the SELECTed recordset.

[quote=455024:@Jean-Yves Pochez]may be you could try this example and adapt it to your needs.
The ExpressionEvaluator class only works on mathematical expressions. From what I’ve read from the initial post, it looks as if the expression involves string operations. So the ExpressionEvaluator class would not be of any use here. XojoScript is the closest thing to an eval function. There is no question that it could assemble the SQL query. The question is whether you can do the actual database access from within XojoScript.

Rick - a function. Clever idea, I’ll try that soon. Thanks