Fork me on GitHub
#sql
<
2019-07-15
>
seancorfield00:07:31

@darioszr It's whatever the default is for the JDBC driver being used.

clj 4
dbernal17:07:40

in Honeysql is there a way to explicitly declare a variable as a varchar instead of nvarchar?

seancorfield17:07:38

@dbernal Not sure what you're asking... The JDBC driver is where the type handling is, not HoneySQL.

dbernal17:07:25

I think just specifying the variable as varchar worked. So making sure that the string that I was passing into HoneySQL had "foo AS VARCHAR(40)" attached

dbernal19:07:12

oh, nvm. What I said didn't work. What you said is correct. I need to specify it at the driver level. Is there a way to do it with the clojure.java.jdbc driver?

seancorfield19:07:07

@dbernal The driver will "do the right thing". Can you explain why you think you need to tell the driver to do something different for some particular column?

seancorfield19:07:57

If the DB column is nvarchar, the value should be inserted/updated as that type of value automatically.

seancorfield19:07:47

clojure.java.jdbc is not a "driver" by the way, it is a wrapper for whatever JDBC driver you are using.

dbernal19:07:23

yea, sorry. I'm using the jtds driver not clojure.java.jdbc

dbernal19:07:13

my query is declaring an nvarchar when the underlying DB value is varchar which is creating some performance issues when doing the conversion. So I need to ensure that the input variables into my query are declared as varchar

dbernal19:07:11

If I understand correctly what you're saying the driver should understand that the column is varchar and therefore declares the variable as varchar?

seancorfield20:07:54

@dbernal I'm not sure what you mean by "my query is declaring an nvarchar" -- queries don't "declare" types...

seancorfield20:07:31

Can you provide some more concrete context for this? Share some code?

seancorfield20:07:29

clojure.java.jdbc and next.jdbc don't do anything with types -- they just pass everything through to the driver (as Object, essentially) and leave it up to the driver to perform any coercion necessary.

dbernal22:07:34

so something like this

DECLARE @P0 BIGINT,
 @P1 BIGINT,
 @P53 NVARCHAR(4000), -- VARCHAR
 @P54 BIGINT,
 @P55 BIGINT,
 @P56 BIGINT,
 @P57 BIGINT,
 @P58 NVARCHAR(4000),  -- VARCHAR
 @P59 BIGINT,
 @P60 NVARCHAR(4000), -- VARCHAR
 @P61 NVARCHAR(4000), -- VARCHAR
 @P62 NVARCHAR(4000), -- VARCHAR
 @P63 NVARCHAR(4000), -- VARCHAR
 @P64 BIGINT,
 @P65 BIGINT
I think the JTDS driver is taking one of the strings I'm sending as input and converting it into an NVARCHAR when I need it to be a VARCHAR. I realize now that the jdbc wrappers don't do anything with types. I think the issue I'm having now is with the driver

seancorfield22:07:30

@dbernal Is that SQL something to do with stored procedures? I've never used DECLARE...

dbernal23:07:56

I'm using SQL Server. Maybe that's why. That's the underlying query that gets made

seancorfield23:07:53

Interesting... Have you tried the official MS driver, just to see if the behavior is the same?

seancorfield23:07:07

(now that it's available as a regular dependency on Maven!)

dbernal01:07:01

oh interesting, I have not tried that yet. I'll give that a go!