Exposed
Exposed copied to clipboard
how to use INSERT INTO tableName (name) values(HEX(DES_ENCRYPT("test",121121')))
This should work
fun hex(exp: Expression<String>) = CustomStringFunction("HEX", exp)
fun des_encrypt(value: String, key: String) = CustomStringFunction("DES_ENCRYPT", stringParam(value), stringParam(key))
FooTable.insert {
it[name] = hex(des_encrypt("test", "121121"))
}
这应该工作
fun hex(exp : 表达式< String >)= CustomStringFunction(“ HEX ”,exp) 有趣 DES_ENCRYPT(值: 字符串,键: 字符串)= CustomStringFunction(“ DES_ENCRYPT ”,StringParam中(值),StringParam中(密钥)) FooTable .insert { it [name] = hex(des_encrypt(“ test ”,“ 121121 ”)) }
dataType?
val name = varchar("name", 128).nullable()
Sorry, but I don't understand your question.
Sorry, but I don't understand your question.
After saving is a function string that should be processed
After saving the database
HEX(DES_ENCRYPT('test', '121121'))
It should look something like this FF236DBE5D5723C7C3
object TestTable : Table("test") {
val id = long("id").primaryKey().autoIncrement()
val name = varchar("name", 256).nullable()
}
val nameCustom = hex(desEncrypt("test'", "121121"))
val id = TestTable.insert {
it[name]=nameCustom.toString()
}.getOrNull(TestTable.id)
Ok. I see. You don't need to call .toString()
as it will insert the expression SQL in your column instead of providing expression into query.
This should work;
fun hex(exp: Expression<String?>) = CustomStringFunction("HEX", exp)
fun desEncrypt(value: String, key: String) = CustomStringFunction("DES_ENCRYPT", stringParam(value), stringParam(key))
object TestTable : LongIdTable("test") {
val name = varchar("name", 256).nullable()
}
val nameCustom = hex(desEncrypt("test", "121121"))
val id = TestTable.insertAndGetId {
it[name] = nameCustom
}
Ok. I see. You don't need to call
.toString()
as it will insert the expression SQL in your column instead of providing expression into query. This should work;fun hex(exp: Expression<String?>) = CustomStringFunction("HEX", exp) fun desEncrypt(value: String, key: String) = CustomStringFunction("DES_ENCRYPT", stringParam(value), stringParam(key)) object TestTable : LongIdTable("test") { val name = varchar("name", 256).nullable() } val nameCustom = hex(desEncrypt("test", "121121")) val id = TestTable.insertAndGetId { it[name] = nameCustom }
Type mismatch if you don't call toString()
it [name] type is String?
,nameCustom type is CustomFunction<String?>
@173889818, there is setter with Expression type, so it should work. Just copy-paste my code and check the compilation.
object MyTbl: Table("sch.tbl") {
val id = varchar("id", 36)
val reasonUniqueId = varchar("reason_unique_id", 50)
}
val uuidGen = CustomStringFunction("UUID")
MyTbl
.update({ MyTbl.id eq "someVal" }) {
it[reasonUniqueId] = uuidGen
}
this code fails - can't find setter
upd: changing to
val reasonUniqueId = varchar("reason_unique_id", 50).nullable
solves.
not what I wanted, but it's another question, anyway.
@seik0ixtem The CustomXFunction
shortcuts are inherently nullable, producing typed results like CustomFunction<X?>
.
If this is not the behavior you want, as your table column should not be nullable, then you just need to create a CustomFunction<X>
directly without using the shortcut. The following compiles with no issue:
object MyTbl : Table("sch.tbl") {
val id = varchar("id", 36)
val reasonUniqueId = varchar("reason_unique_id", 50)
}
// only change here
val uuidGen = CustomFunction<String>("UUID", VarCharColumnType())
MyTbl
.update({ MyTbl.id eq "someVal" }) {
it[reasonUniqueId] = uuidGen
}