Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@svenallers
Copy link
Contributor

@svenallers svenallers commented Jul 21, 2022

Hi,
I realized during some implementation that a cast you make is actually not applied. I fixed that by overriding visitCasting() in SqlFormatter. During the implementation of visitCasting() , I also realized that

if (expr.removeBrackets) {
    visit(expr)
} else {
    write("(")
    visit(expr)
    removeLastBlank()
    write(") ")
}

was a very common pattern used all over the place. I took the chance and refactored it into a single method writeExpression() to reduce the redundancy. I hope that's fine. Otherwise, I would revert it.

@svenallers
Copy link
Contributor Author

resolves #146

@vincentlauvlwj
Copy link
Member

vincentlauvlwj commented Jul 21, 2022

Thanks for your contribution, the code is perfect, but we have to ensure the cast syntax works for all supported dialects, could you please add unit tests for each of them?

write("CAST(")
writeExpression(expr.expression)
write("AS ${expr.sqlType.typeName}) ")
return expr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the writeKeyword function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@svenallers
Copy link
Contributor Author

@vincentlauvlwj I added tests for each dialect. Was not as easy as I expected, because every dialect has its own restrictions as to what cast is allowed and MySql, Oracle as well as SQL Server do not allow casts from int to text...

@vincentlauvlwj vincentlauvlwj changed the base branch from master to v3.6.x July 22, 2022 03:03
@vincentlauvlwj vincentlauvlwj merged commit 22e7b30 into kotlin-orm:v3.6.x Jul 22, 2022
@vincentlauvlwj
Copy link
Member

Merged, will release in next version.

@svenallers svenallers deleted the implement-casting branch July 22, 2022 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants