mirror of
https://github.com/dimitri/pgloader.git
synced 2026-05-05 02:46:10 +02:00
Be smarter about MSSQL column_default values, fix #207.
MS SQL default values can be quite... sophisticated, so get around with using a more complex expression in the SQL query that retrieve the default values. The query and implementation has been largely provided by luqelinux and jstans github users, and I finally merged manually their cumulated efforts on this front.
This commit is contained in:
parent
3848ad6ae5
commit
8e6e67f056
@ -100,7 +100,25 @@
|
||||
c.table_name,
|
||||
c.column_name,
|
||||
c.data_type,
|
||||
c.column_default,
|
||||
CASE
|
||||
WHEN c.column_default LIKE '((%' AND c.column_default LIKE '%))' THEN
|
||||
CASE
|
||||
WHEN SUBSTRING(c.column_default,3,len(c.column_default)-4) = 'newid()' THEN 'generate_uuid_v4()'
|
||||
WHEN SUBSTRING(c.column_default,3,len(c.column_default)-4) LIKE 'convert(%varchar%,getdate(),%)' THEN 'today'
|
||||
WHEN SUBSTRING(c.column_default,3,len(c.column_default)-4) = 'getdate()' THEN 'now'
|
||||
WHEN SUBSTRING(c.column_default,3,len(c.column_default)-4) LIKE '''%''' THEN SUBSTRING(c.column_default,4,len(c.column_default)-6)
|
||||
ELSE SUBSTRING(c.column_default,3,len(c.column_default)-4)
|
||||
END
|
||||
WHEN c.column_default LIKE '(%' AND c.column_default LIKE '%)' THEN
|
||||
CASE
|
||||
WHEN SUBSTRING(c.column_default,2,len(c.column_default)-2) = 'newid()' THEN 'generate_uuid_v4()'
|
||||
WHEN SUBSTRING(c.column_default,2,len(c.column_default)-2) LIKE 'convert(%varchar%,getdate(),%)' THEN 'today'
|
||||
WHEN SUBSTRING(c.column_default,2,len(c.column_default)-2) = 'getdate()' THEN 'now'
|
||||
WHEN SUBSTRING(c.column_default,2,len(c.column_default)-2) LIKE '''%''' THEN SUBSTRING(c.column_default,3,len(c.column_default)-4)
|
||||
ELSE SUBSTRING(c.column_default,2,len(c.column_default)-2)
|
||||
END
|
||||
ELSE c.column_default
|
||||
END,
|
||||
c.is_nullable,
|
||||
COLUMNPROPERTY(object_id(c.table_name), c.column_name, 'IsIdentity'),
|
||||
c.CHARACTER_MAXIMUM_LENGTH,
|
||||
|
||||
@ -150,11 +150,12 @@
|
||||
(defun float-to-string (float)
|
||||
"Transform a Common Lisp float value into its string representation as
|
||||
accepted by PostgreSQL, that is 100.0 rather than 100.0d0."
|
||||
(declare (type (or null float) float))
|
||||
(declare (type (or null float string) float))
|
||||
(when float
|
||||
(typecase float
|
||||
(double-float (let ((*read-default-float-format* 'double-float))
|
||||
(princ-to-string float)))
|
||||
(string float)
|
||||
(t (princ-to-string float)))))
|
||||
|
||||
(defun set-to-enum-array (set-string)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user