Fork me on GitHub
#sql
<
2019-10-30
>
fabrao16:10:40

hello all, I have a monitoring processa that read results from sqlserver database. Sometimes the result query does not came up and the cicle pool does not repeat, even I configure timeout for it. Is there any way to have outside timeout?

seancorfield16:10:56

@fabrao I'm not sure I understand what you're asking... Are you saying the query just "hangs" indefinitely? How are you configuring the timeout?

fabrao16:10:21

Yes -> "Are you saying the query just "hangs" indefinitely?" {:timeout 100 :dbtype "mssql"}

seancorfield16:10:04

What makes you think that sets a timeout?

fabrao16:10:09

is it does not?

fabrao16:10:47

Release 0.3.6 on 2014-10-28

Arbitrary values allowed for :cursors, :concurrency, :result-type arguments to prepare-statement JDBC-102.
Allow :as-arrays? :cols-as-is to omit column name uniqueness when returning result sets as arrrays JDBC-101.
Add :timeout argument to prepare-statement JDBC-100.

seancorfield16:10:22

That's an ancient version of clojure.java.jdbc.

seancorfield16:10:49

I'm looking at the code now to see what it actually does.

fabrao16:10:30

so, have I to replace it to next-jdbc?

seancorfield16:10:49

Hmm, OK, that should call .setQueryTimeout on the statement when you (or c.j.j.) calls prepare-statement...

seancorfield16:10:34

I don't believe that option in a db-spec is propagated to prepare-statement from query but I'd have to do some debugging to be certain.

fabrao16:10:36

oh, sorry about using it in wrong way, I have to replace or complement it in many funcs

seancorfield16:10:17

I think if you put :queryTimeout 100 in the db-spec instead of just :timeout it will work.

fabrao16:10:32

I´m thinking using this

(defn wait [ms f & args]
  (let [c (chan)]
    (go (>! c (apply f args)))
    (first (alts!! [c (timeout ms)]))))
for query timeout, is that ok?

seancorfield16:10:58

:queryTimeout and :cancelTimeout (and a bunch of other timeouts) are supported at the DriverManager level for MS SQL's standard JDBC driver.

seancorfield16:10:29

Not sure how you think that core.async code is going to affect anything about a JDBC query?

fabrao16:10:41

what other alternatives do I have?

seancorfield16:10:20

Actually, now I look at the code in more detail, it does look like :timeout in the db-spec should be merged with the options passed to query and then into prepare-statement... But maybe .setQueryTimeout on the (prepared) statement is not sufficient for whatever use case you have with your query...?

fabrao16:10:13

I´m using it with jdbc/query

seancorfield16:10:13

Yes, I figured. That's not what I meant.

seancorfield17:10:01

There are all sorts of timeouts that can be set when a connection is created against the MS SQL driver https://docs.microsoft.com/en-us/sql/connect/jdbc/setting-the-connection-properties?view=sql-server-ver15

fabrao17:10:04

as I see, :timeout will not affect that

fabrao17:10:21

yes, I´ll try to use againts connection

seancorfield17:10:38

I don't think you are understanding me correctly 😐

seancorfield17:10:16

Share more of your code. I need to see what arguments you're passing to query and how/whether you are getting a connection or transaction first, or relying on query to do that.

fabrao17:10:14

I´m just using (jdbc/query db-spec [query]) with db-spec as

{:host "10.10.20.70"
                      :port 1433 :timeout 100
                      :dbname "monitoramento"
                      :user "admin"
                      :password #senha "************"}

seancorfield17:10:47

OK, that will pass timeout as a property to DriverManager/getConnection which will do nothing, but it should also pass timeout into the prepare-statement call behind the scenes which should call .setQueryTimeout on the PreparedStatement object which I would hope MS SQL's JDBC driver supports.

seancorfield17:10:47

But I would definitely try :queryTimeout and maybe :cancelTimeout in the db-spec hash map and see if that works better.

fabrao17:10:43

Thanks, I´ll give a try