SQL Server Introspection crashes on multi-line (deprecated) defaults #24275
Description
With this SQL:
/* This is a comment */
CREATE DEFAULT [dbo].[valueZero] AS 0;
CREATE TABLE [dbo].[A] (
id INT IDENTITY,
val INT NOT NULL
);
sp_bindefault '[dbo].[valueZero]', '[dbo].[A].[val]'
(Make sure that the comment in line 1 is included when you create the default, in DBeaver for example by selecting both lines before executing the statement.)
db pull
will crash on Introspection:
✖ Introspecting based on datasource defined in prisma\schema.prisma
Oops, an unexpected error occurred!
Error in Schema engine.
Reason: [schema-engine\sql-schema-describer\src\mssql.rs:348:30] called `Result::unwrap()` on an `Err` value: "Couldn't parse default value: `/* This is a comment */\r\nCREATE DEFAULT [dbo].[valueZero] AS 0;\r\n`"
The underlying Introspection query is this one:
https://github.com/prisma/prisma-engines/blob/b4fe3e61b0e65aba302a47e5e94bf961f6ef2fc2/schema-engine/sql-schema-describer/src/mssql.rs#L268C13-L290C81
The gist of it is this simplified query:
SELECT OBJECT_DEFINITION(c.default_object_id)
FROM sys.columns c
INNER JOIN sys.objects obj ON c.object_id = obj.object_id
WHERE obj.is_ms_shipped = 0
The result:
(Note the line breaks in the string.)
Seems this case of the result being a multi-line string crashes our default parsing logic:
https://github.com/prisma/prisma-engines/blob/b4fe3e61b0e65aba302a47e5e94bf961f6ef2fc2/schema-engine/sql-schema-describer/src/mssql.rs#L340C1-L348C39