V25.1.4 - Error saving SQL code to a table

V25.1.4 - Error saving SQL code to a table

guiroehe
Collaborator Collaborator
95 Views
2 Replies
Message 1 of 3

V25.1.4 - Error saving SQL code to a table

guiroehe
Collaborator
Collaborator

Hello, 

 

please see the attached example. Nor the model is relevant neither the "sendToPort" logic, besides having a SQL statement on it. Now, please see the two sourced scripts. In those, the objective is to save the send to port code to a cell on a table. The only difference between them is on row 6.

 

It seems your SQL engine is interpreting the content of the variable as part of the SQL statement itself. This seems to defeat the concept of SQL as a way to convey content to tables; in other words, a bug.If it is a bug, how to fix it, even provisionally?

 

If this is not a bug, what is the proper way to save the content of a string containing an SQL statement to a table, using SQL?

 

Please note this is a mock-up example. It reflects a more complex modeling where SQL is used extensively to convey content from/to tables.

 

Thank you.

0 Likes
96 Views
2 Replies
Replies (2)
Message 2 of 3

joerg_vogel_HsH
Mentor
Mentor

Maybe my answer is totally wrong. 
As I started with SQL in FlexSim, I learned that SQL is working with temporary tables. Query results are temporary tables, too. You do not address nor update a referenced table directly in a clause. You can copy from a result table in FlexSim values to a global table or other tree nodes. 
SQL is an additional language environment. As Flexscript it acts in a simplified scope.
What you see as an error is a problem of preparing a clause inside the SQL interpreter. What is a clause, what is a value? The interpreter gets as an input only a string. There are round brackets, curled brackets square brackets and different kinds of quotes to distinguish between different data types. FlexSim itself allows a code injection of Flexscript directly, which is obviously not a default option of a common SQL interpreter. 

The opposite of your question is discussed as how to prevent code injection in SQL clauses. But this is a common discussion and not a specific for Flexscript alone.

 

I noticed you are still exploring how to build a model dynamically from within a running model. It is often mentioned that there are restrictions in such an approach, because a model depends on a compilation. Currently you do not see this anymore. In early versions of FlexSim an external compiler had to be installed to start a model run. This compilation is a result of a reset. If you want to update a model while it is running, you have to consider how you can reset and restart it externally outside a model run, because there is not a scheduler inside of FlexSim engine which you can update to run a model automatically from the program itself. 

0 Likes
Message 3 of 3

guiroehe
Collaborator
Collaborator

Hello, @joerg_vogel_HsH ,

 

thank you for your answer, but I believe your interpretation is not quite my intention. To clarify:

 

I am not intending to configure a "hot" dynamical model; I am saving modeled conditions and scripts on a global table, as in the example I sent. The script being saved is a string. Saving a string on a cell of a global table should not be a problem; the fact that that particular string has a written text that is an SQL statement should not affect the behavior of saving a string to a global-table cell (and there is nothing on FlexSim's documentation saying it is not possible).

 

I still need a solution for that. 

 

In addition: I can (maybe) understand the architectural choice of having FlexSim's SQL tokenizer to interpret the <<content>> of a string as part of the clause itself. I strongly disagree from it, conceptually, as it breaks one of the most basic rules of scoping: a variable is not its value. Even if having to live with this engine-implementation flaw (break of scope integrity), I cannot understand why encapsulating the string with JSON.stringify still allows the tokenizer to look at the content of the encapsulated variable.

 

I hope this clarifies the problem and the solution I am in need of.

 

Thank you.