https://kotlinlang.org logo
#exposed
Title
# exposed
z

zt

02/16/2022, 2:52 AM
I'm trying to modify an existing value in my update statement as follows
Copy code
Guild.update({ Guild.id eq guild.id.toString() }) {
    it[data] = data + "abc"
}
For some reason, it always sets the value to "0" The table is defined like this
Copy code
object Guild : Table() {
    val id = varchar("id", 18)
    val data = text("data").default("")

    override val primaryKey = PrimaryKey(id)
}
If I use
it[data] = "whatever"
then it actually sets to the proper value
d

dave08

02/16/2022, 4:07 AM
There's probably a concat function... I don't think you can append a field's value like that... How would exposed know how to generate the sql for that?
s

spand

02/16/2022, 10:23 AM
From the looks of it you are not wrapping it in
with(SqlExpressionBuilder) {
as the example is
z

zt

02/16/2022, 3:45 PM
I tried that too but nothing changed
b

Bogdan

02/17/2022, 4:44 PM
Feature not supported: "CLOB +"; SQL statement:
UPDATE GUILD SET "DATA"=(GUILD."DATA" + '1') WHERE GUILD.ID = '1'
Copy code
Guild.update({ Guild.id eq guildId }) {
    it[value] = value + 1 //  work, import org.jetbrains.exposed.sql.SqlExpressionBuilder.plus
    with(SqlExpressionBuilder) {
         it[value] = value + 1 // work
        // it[data] = data + "1" not work, error
        it[data] = concat(data, stringLiteral("123"))
    }
}
value = integer log:
Copy code
SQL: UPDATE GUILD SET "VALUE"=(GUILD."VALUE" + 1), "DATA"=CONCAT(GUILD."DATA", '123') WHERE GUILD.ID = '1'
com.example.Guild.id=1, com.example.Guild.data=clob1: 'data123', com.example.Guild.value=1
Copy code
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.concat
import org.jetbrains.exposed.sql.SqlExpressionBuilder.plus // +
import org.jetbrains.exposed.sql.transactions.transaction

fun main() {
// transaction 
Guild.update({ Guild.id eq guildId }) {
    it[value] = value + 1 
    it[data] = concat(data, stringLiteral("123"))
}

object Guild : Table() {
    val id = varchar("id", 18)
    val data = text("data").default("")
    val value = integer("value").default(0)

    override val primaryKey = PrimaryKey(id)
}
👍 1
z

zt

02/17/2022, 6:34 PM
This worked, thank you so much!
4 Views