How can I use LOOP macro with expression?
Hellow!
I want get code as follow:
TABLE_NAME is declared as static field through LOOP macro. COLUMN_NAME is declared as static field through double LOOP macro.
I created follow generator's template:
I don't know how can I insert code with columns names and types in the expression. I try to use LOOP macro, but it does not work. Tell me, please, how can I do it.
I want get code as follow:
Code
String query = "CREATE TABLE "
+ TABLE_NAME + " ("
+ COLUMN_NAME1 + " column_type," //where column_type is one of SQLite data type
+ COLUMN_NAME2 + " column_type,"
+ ... + ");";
TABLE_NAME is declared as static field through LOOP macro. COLUMN_NAME is declared as static field through double LOOP macro.
I created follow generator's template:
I don't know how can I insert code with columns names and types in the expression. I try to use LOOP macro, but it does not work. Tell me, please, how can I do it.
Please sign in to leave a comment.
for a working answer it would be good to know how your language is structured. For your goal I assume you have (or should have) a table concept with column concept children in it. Then you should create a template with the table name as property node macro to table.name and loop over table.columns. In the loop you can add property macros for the column names and column types.
Best regards,
Jens
I'm trying to add node LOOP macro to COLUMN by node.attributes
But I see follow error:
Error: Target role for $LOOP$ macro can contain max 1 element (role: rightExpression)
I want to get String value on Java-language with query to create new table in SQLite database, using Entity.name as TABLE and EntityAttribute as COLUMN.
thanks, now I can see what you mean. The loop macro takes one input node and loops over a collection defined in the inspector. But you have a bunch of StaticFieldDeclarations (which are the COLUMNs), so this doesn't work and you have to find another solution. If I may suggest one: in your onCreate-method, use a StringBuilder instead of a String. Write builder.append("dummy"); and wrap this statement into the LOOP macro. Add a property macro to the "dummy" and build the column string as the property. I guess you need the name, the data type, and perhaps some constraints like NULL/NOT NULL, foreign key and so on.
Best regards,
Jens
Are there any other solutions, which lead to more readable results?
Best regards,
Jens