Skip to content

feat: add handling of graph tables at FakeTable procedure #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Source/tSQLt.FakeTable.ssp.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ BEGIN
DECLARE @TargetObjectFullName NVARCHAR(MAX) = NULL;
DECLARE @OriginalObjectObjectId INT;
DECLARE @TargetObjectObjectId INT;

DECLARE @IsNode BIT = 0;
DECLARE @IsEdge BIT = 0;

IF(@TableName NOT IN (PARSENAME(@TableName,1),QUOTENAME(PARSENAME(@TableName,1)))
AND @SchemaName IS NOT NULL)
BEGIN
Expand All @@ -31,6 +33,11 @@ BEGIN

SET @OrigObjectFullName = @OrigObjectCleanQuotedSchemaName + '.' + @OrigObjectCleanQuotedName;

-- Retrieve node and edge information for the original object
SELECT
@IsNode = is_node, @IsEdge = is_edge FROM sys.tables
WHERE [name] = PARSENAME(@OrigObjectFullName,1) AND schema_name([schema_id]) = PARSENAME(@OrigObjectFullName,2);

EXEC tSQLt.Private_RenameObjectToUniqueName @OrigObjectCleanQuotedSchemaName, @OrigObjectCleanQuotedName, @OrigObjectNewName OUTPUT;

SET @OriginalObjectObjectId = OBJECT_ID(@OrigObjectCleanQuotedSchemaName + '.' + QUOTENAME(@OrigObjectNewName));
Expand All @@ -52,7 +59,7 @@ BEGIN
SET @TargetObjectObjectId = @OriginalObjectObjectId;
END;

EXEC tSQLt.Private_CreateFakeOfTable @OrigObjectCleanQuotedSchemaName, @OrigObjectCleanQuotedName, @TargetObjectObjectId, @Identity, @ComputedColumns, @Defaults;
EXEC tSQLt.Private_CreateFakeOfTable @OrigObjectCleanQuotedSchemaName, @OrigObjectCleanQuotedName, @TargetObjectObjectId, @Identity, @ComputedColumns, @Defaults, @IsNode, @IsEdge;

EXEC tSQLt.Private_MarktSQLtTempObject @OrigObjectFullName, N'TABLE', @OrigObjectNewName;
END
Expand Down
6 changes: 4 additions & 2 deletions Source/tSQLt.Private_CreateFakeOfTable.ssp.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ CREATE PROCEDURE tSQLt.Private_CreateFakeOfTable
@OrigTableObjectId INT,
@Identity BIT,
@ComputedColumns BIT,
@Defaults BIT
@Defaults BIT,
@IsNode BIT = 0,
@IsEdge BIT = 0
AS
BEGIN
DECLARE @cmd NVARCHAR(MAX) =
(SELECT CreateTableStatement
FROM tSQLt.Private_CreateFakeTableStatement(@OrigTableObjectId, @SchemaName+'.'+@TableName,@Identity,@ComputedColumns,@Defaults,0));
FROM tSQLt.Private_CreateFakeTableStatement(@OrigTableObjectId, @SchemaName+'.'+@TableName,@Identity,@ComputedColumns,@Defaults,0, @IsNode, @IsEdge));
EXEC (@cmd);
END;
---Build-
Expand Down
11 changes: 9 additions & 2 deletions Source/tSQLt.Private_CreateFakeTableStatement.sfn.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ CREATE FUNCTION tSQLt.Private_CreateFakeTableStatement(
@Identity BIT,
@ComputedColumns BIT,
@Defaults BIT,
@PreserveNOTNULL BIT
@PreserveNOTNULL BIT,
@IsNode BIT = 0,
@IsEdge BIT = 0
)
RETURNS TABLE
AS
RETURN
SELECT
'CREATE TABLE ' + @FullFakeTableName + '(' + STUFF(Cols,1,1,'') + ')' CreateTableStatement,
'CREATE TABLE ' + @FullFakeTableName + '(' + STUFF(Cols,1,1,'')
+ CASE
WHEN @IsNode = 1 THEN ') AS NODE'
WHEN @IsEdge = 1 THEN ') AS EDGE'
ELSE ')'
END CreateTableStatement,
'CREATE TYPE ' + @FullFakeTableName + ' AS TABLE(' + STUFF(Cols,1,1,'') + ')' CreateTableTypeStatement
FROM
(
Expand Down