jOOQ use throw clause in SQLSERVER2008 Create Statement

31 views
Skip to first unread message

mats...@googlemail.com

unread,
Jul 11, 2016, 6:41:43 AM7/11/16
to jOOQ User Group
Hello together,

i've created a 'create table' statement with DSLCONTEXT.createTableIfNotExists (SQLDialect is set to SQLSERVER2008).

jOOQ generates the following sql:

begin try create table
...
end try begin catch if error_number() != 2714 throw; end catch

The execution of the Sql throws an SQLException:
com.microsoft.sqlserver.jdbc.SQLServerException: Falsche Syntax in der Nähe von 'throw'.

Throw Statement is only supported up to SQL Server 2012... isnt it?

Greetings
Matthias

Lukas Eder

unread,
Jul 11, 2016, 11:31:17 AM7/11/16
to jooq...@googlegroups.com
Hi Matthias,

Thank you very much for bringing this to our attention. Indeed, the current implementation doesn't work with SQL Server 2008, only with 2012 onwards. I have registered an issue to fix this:

I guess in 2008, we'll have to use raiserror instead...

Thanks again for reporting,
Lukas

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lukas Eder

unread,
May 4, 2017, 11:49:22 AM5/4/17
to jOOQ User Group
For the record, jOOQ 3.10 (and patch releases 3.9.3 and 3.8.8) will now emulate DROP TABLE IF EXISTS [t2] (and similar) with the following statement in SQL Server 2008:

begin try
  drop
table [t2]

end try

begin catch

  if error_number() != 3701 begin

    declare @ErrorMessage nvarchar(4000) = ERROR_MESSAGE();

    declare @ErrorSeverity int = ERROR_SEVERITY();

    declare @ErrorState int = ERROR_STATE();

    raiserror (@ErrorMessage, @ErrorSeverity, @ErrorState);

  end;

end catch

To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages