Initialize MSSQL library when used

This commit is contained in:
Tuan Le 2024-01-16 18:15:18 +01:00
parent 2079646c81
commit 14cf7c0955

View File

@ -151,35 +151,38 @@
`(lambda () `(lambda ()
;; now is the time to load the CFFI lib we need (freetds) ;; now is the time to load the CFFI lib we need (freetds)
(let (#+sbcl(sb-ext:*muffled-warnings* 'style-warning)) (let (#+sbcl(sb-ext:*muffled-warnings* 'style-warning))
(cffi:load-foreign-library 'mssql::sybdb)) (cffi:load-foreign-library 'mssql::sybdb)
(mssql:init))
(let* ((*default-cast-rules* ',*mssql-default-cast-rules*) (unwind-protect
(*cast-rules* ',casts) (let* ((*default-cast-rules* ',*mssql-default-cast-rules*)
(*mssql-settings* ',mssql-gucs) (*cast-rules* ',casts)
(on-error-stop (getf ',options :on-error-stop t)) (*mssql-settings* ',mssql-gucs)
,@(pgsql-connection-bindings pg-db-conn gucs) (on-error-stop (getf ',options :on-error-stop t))
,@(batch-control-bindings options) ,@(pgsql-connection-bindings pg-db-conn gucs)
,@(identifier-case-binding options) ,@(batch-control-bindings options)
(source ,@(identifier-case-binding options)
(make-instance 'copy-mssql (source
:target-db ,pg-db-conn (make-instance 'copy-mssql
:source-db ,ms-db-conn))) :target-db ,pg-db-conn
:source-db ,ms-db-conn)))
,(sql-code-block pg-db-conn :pre before "before load") ,(sql-code-block pg-db-conn :pre before "before load")
(copy-database source (copy-database source
:including ',including :including ',including
:excluding ',excluding :excluding ',excluding
:alter-schema ',alter-schema :alter-schema ',alter-schema
:alter-table ',alter-table :alter-table ',alter-table
:after-schema ',after-schema :after-schema ',after-schema
:materialize-views ',views :materialize-views ',views
:distribute ',distribute :distribute ',distribute
:set-table-oids t :set-table-oids t
:on-error-stop on-error-stop :on-error-stop on-error-stop
,@(remove-batch-control-option options)) ,@(remove-batch-control-option options))
,(sql-code-block pg-db-conn :post after "after load")))) ,(sql-code-block pg-db-conn :post after "after load"))
(mssql:exit))))
(defrule load-mssql-database load-mssql-command (defrule load-mssql-database load-mssql-command
(:lambda (source) (:lambda (source)