Question

How to dynamically load a query and create a table using query results

  • 31 October 2022
  • 4 replies
  • 13 views

Badge

I'm trying to pass the sql query dynamically through the webhook url and then execute the query and generate a table using the query results.

I have tried using the SQLCreator

Problem is, It is not able to expose the attributes automatically from the SQL query if passed dynamically.

Is there any other transformers which would help me execute this?


4 replies

Userlevel 6
Badge +31

This can be done using a dynamic workflow where you use a schema feature to set the schema in the writer at runtime. This schema schema feature can be generated using a SchemaScanner transformer.

For more info on this, check Tutorial: Dynamic Workflows or more specific, Dynamic Workflows: Destination Schema is Derived from a Schema Feature and How to Use the SchemaScanner Transformer.

 

Badge +3

If you know the attribute names, you can forcefully input the field names or alias names in the text box of the SQL executor or SQL creator, or you can give aliases for each field in a SQL query.

Additionally, these attributes will be automatically filled up while the query is running.

also

 

For the first time, when building FME, you can hard code the SQL and generate all possible attributes.

 

Badge

Here I would need to generate the dataset from the SQL query that is passed by the user, and each time the query would be different.

So the reader would be executing the query and writer will write the query results to the database.

I have used SQL creator, but it is not able to fetch the attributes on the go, any alternate solution for this would be appreciated.

Userlevel 3
Badge +16

Your SQL statement is executing correctly, it is getting the attributes, but the attributes aren't Exposed. That's not a problem though - attributes don't need to be exposed when outputting with a writer set to Dynamic, the writer just needs to receive a special schema feature along with the data features to tell it what the attributes are to write out.

Since FME 2022, the SQL Creator has a <Schema> port which should make this easier. The links in Niels' reply above describe all you need for dynamic writing.

 

One other thing, SQL injection is problem to consider with this approach. You'll want to make sure the SQL query is safe to execute, to prevent misuse.

Reply