Fork me on GitHub
#sql
<
2017-03-02
>
plins21:03:31

hello everyone, im new to clojure and the JVM in general... i have an existing database, which is, unfortunately full of triggers .. i have a field (phone region prefix) which isnt optional ( you have to provide a value ), but there are triggers that calculate those values and input them for me if i try to make a insert statement on the mysql CLI, everything goes fine, but when i try to run it via JDBC I get an java exception java.sql.SQLException: field 'ddd' doesn't have a default value

plins21:03:21

is there a way to mimic the CLI behaviour?

(defn create-usuer
  [^String email ^String phone ^String username ^String cpf]
  (jdbc/insert! db :tb_usuario {:tipo "p"
                                :logado 0
                                :ativo 1
                                :idPaisTelefone1 1
                                :telefone1 phone
                                :usuario email
                                :email email
                                :senha "hash the cpf"
                                :celular phone
                                :cpf cpf
                                :dataCriacao "NOW()"
                                :dataAtualizacao "NOW()"
                                :nome username}))
this is how im trying to insert it

seancorfield21:03:56

I’m surprised the insert via CLI allows you to omit ddd given that it’s non-null and has no default value. The exception you get is exactly what I’d expect from JDBC: a non-null field with no default value has to have some value provided in the insert statement.

seancorfield21:03:26

The triggers only fire “after” the insert so you have to satisfy that basic constraint first.

seancorfield21:03:14

Ah, I see you also asked this in #clojure and got pointed to a forum posting as to why the CLI behavior differs...

plins21:03:45

thanks for the fast response 🙂

seancorfield21:03:13

I see you also posted to the java.jdbc mailing list, so I’ll post that forum link in response so folks have that information in the archives (thanks @hiredman )