+
Skip to content

Use table visitor when inserting data #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,9 @@ public abstract class SqlFormatter(

override fun visitInsert(expr: InsertExpression): InsertExpression {
writeKeyword("insert into ")
write("${expr.table.name.quoted} (")
visit(expr.table)
write(" (")

for ((i, assignment) in expr.assignments.withIndex()) {
if (i > 0) write(", ")
checkColumnName(assignment.column.name)
Expand All @@ -550,7 +552,8 @@ public abstract class SqlFormatter(

override fun visitInsertFromQuery(expr: InsertFromQueryExpression): InsertFromQueryExpression {
writeKeyword("insert into ")
write("${expr.table.name.quoted} (")
visit(expr.table)
write(" (")
for ((i, column) in expr.columns.withIndex()) {
if (i > 0) write(", ")
checkColumnName(column.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class PostgreSqlTest : BaseTest() {
}

@Test
fun testSchema() {
fun testSchemaUpdate() {
val t = object : Table<Department>("t_department", catalog = postgres.databaseName, schema = "public") {
val id = int("id").primaryKey().bindTo { it.id }
val name = varchar("name").bindTo { it.name }
Expand All @@ -378,6 +378,22 @@ class PostgreSqlTest : BaseTest() {
assert(database.sequenceOf(t.aliased("t")).mapTo(HashSet()) { it.name } == setOf("test", "finance"))
}

@Test
fun testSchemaInsert() {
val t = object : Table<Department>("t_department", catalog = postgres.databaseName, schema = "public") {
val id = int("id").primaryKey().bindTo { it.id }
val name = varchar("name").bindTo { it.name }
}

database.insert(t) {
set(it.id, 1)
set(it.name, "test")
}

assert(database.sequenceOf(t).filter { it.id eq 1 }.mapTo(HashSet()) { it.name } == setOf("test"))
assert(database.sequenceOf(t.aliased("t")).mapTo(HashSet()) { it.name } == setOf("test", "finance"))
}

@Test
fun testMaxColumnNameLength() {
val t = object : Table<Nothing>("t_long_name") {
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载