Fork me on GitHub
#sql
<
2020-06-18
>
isak20:06:48

Since jdbc doesn't support reusing parameters, it seems like it would be smart to just add a declare @x nvarchar(50) = ?; type statements at the top of the queries (if they need to reuse parameters). Anyone see any problems with that?

hiredman21:06:17

yes, I would not trust the scoping of those variables

hiredman21:06:51

passing in parameters multiple times is nice and simple compared to adding mutable variables that may be connection scoped and passed around through your connection pool

isak21:06:34

For the db I'm using (SQL Server), there is only one special kind of thing that has connection scope (not normal declares like above). For passing the variable multiple times, I can see it being fine if you can assume it is tiny, but what if you can't? For example, if big json documents are sometimes passed