Skip to content

Commit 14cf7c0

Browse files
committed
Initialize MSSQL library when used
1 parent 2079646 commit 14cf7c0

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

src/parsers/command-mssql.lisp

+32-29
Original file line numberDiff line numberDiff line change
@@ -151,35 +151,38 @@
151151
`(lambda ()
152152
;; now is the time to load the CFFI lib we need (freetds)
153153
(let (#+sbcl(sb-ext:*muffled-warnings* 'style-warning))
154-
(cffi:load-foreign-library 'mssql::sybdb))
155-
156-
(let* ((*default-cast-rules* ',*mssql-default-cast-rules*)
157-
(*cast-rules* ',casts)
158-
(*mssql-settings* ',mssql-gucs)
159-
(on-error-stop (getf ',options :on-error-stop t))
160-
,@(pgsql-connection-bindings pg-db-conn gucs)
161-
,@(batch-control-bindings options)
162-
,@(identifier-case-binding options)
163-
(source
164-
(make-instance 'copy-mssql
165-
:target-db ,pg-db-conn
166-
:source-db ,ms-db-conn)))
167-
168-
,(sql-code-block pg-db-conn :pre before "before load")
169-
170-
(copy-database source
171-
:including ',including
172-
:excluding ',excluding
173-
:alter-schema ',alter-schema
174-
:alter-table ',alter-table
175-
:after-schema ',after-schema
176-
:materialize-views ',views
177-
:distribute ',distribute
178-
:set-table-oids t
179-
:on-error-stop on-error-stop
180-
,@(remove-batch-control-option options))
181-
182-
,(sql-code-block pg-db-conn :post after "after load"))))
154+
(cffi:load-foreign-library 'mssql::sybdb)
155+
(mssql:init))
156+
157+
(unwind-protect
158+
(let* ((*default-cast-rules* ',*mssql-default-cast-rules*)
159+
(*cast-rules* ',casts)
160+
(*mssql-settings* ',mssql-gucs)
161+
(on-error-stop (getf ',options :on-error-stop t))
162+
,@(pgsql-connection-bindings pg-db-conn gucs)
163+
,@(batch-control-bindings options)
164+
,@(identifier-case-binding options)
165+
(source
166+
(make-instance 'copy-mssql
167+
:target-db ,pg-db-conn
168+
:source-db ,ms-db-conn)))
169+
170+
,(sql-code-block pg-db-conn :pre before "before load")
171+
172+
(copy-database source
173+
:including ',including
174+
:excluding ',excluding
175+
:alter-schema ',alter-schema
176+
:alter-table ',alter-table
177+
:after-schema ',after-schema
178+
:materialize-views ',views
179+
:distribute ',distribute
180+
:set-table-oids t
181+
:on-error-stop on-error-stop
182+
,@(remove-batch-control-option options))
183+
184+
,(sql-code-block pg-db-conn :post after "after load"))
185+
(mssql:exit))))
183186

184187
(defrule load-mssql-database load-mssql-command
185188
(:lambda (source)

0 commit comments

Comments
 (0)