Noro96
Noro96

Reputation: 113

Generating of query in wrong format

I have a problem with piece of code, which is generated (output) in wrong format and not requested form:

I wanted generate query/sql with foreign key without "ALTER TABLE NameOfTab ADD" so I used this piece of code:

DSL.constraint(DSL.name("fk_example"))
   .foreignKey("id1","id2")
   .references("referecnedTableName", "referencedColumn1", "referencedColumn2");

And here comes a problem because it returns as string this form:

constraint "fk_example"
foreign key (
"id1", 
"id2"
)
references "referecnedTableName" (
"referencedColumn1", 
"referencedColumn2"
)

Expected result is:

constraint fk_example foreign key (id1, id2) 
references referecnedTableName (referencedColumn1, referencedColumn2)

Something similar in correct format does ALTER table:

ctx.alterTable(tableName)
   .add(
      DSL.constraint(DSL.name("fk_example"))
         .foreignKey("id1","id2")
         .references("referecnedTableName","referencedColumn1","referencedColumn2"))
   .getSQL(ParamType.INLINED));

But it returns it with "alter table t3 add ... " and I don't want "alter table" part.

Upvotes: 0

Views: 47

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 221195

You should use DSLContext.render(QueryPart) instead of QueryPart.toString(). The toString() behaviour defaults to calling render() with some unspecified default Settings including the generation of those double quoted identifiers, which I'm suspecting you don't want to have.

Upvotes: 1

Related Questions