Skip to content
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

ResultSetToTable Feature #19

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
6 changes: 6 additions & 0 deletions Experiments/Experiments.ssmssqlproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
<AssociatedConnUserName />
<FullPath>GenerateTestsForResultsetFilterDataTypes.sql</FullPath>
</FileNode>
<FileNode Name="GenerateTestsForResultsetToTableDataTypes.sql">
<AssociatedConnectionMoniker />
<AssociatedConnSrvName />
<AssociatedConnUserName />
<FullPath>GenerateTestsForResultsetToTableDataTypes.sql</FullPath>
</FileNode>
<FileNode Name="LIKE4000.sql">
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:Dev_tSQLt:True</AssociatedConnectionMoniker>
<AssociatedConnSrvName>Dev_tSQLt</AssociatedConnSrvName>
Expand Down
85 changes: 85 additions & 0 deletions Experiments/GenerateTestsForResultsetToTableDataTypes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Copyright 2011 tSQLt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JonathanHallKJR , this all looks great. We'd like to make some small modifications, but critically, we can't use copyrighted code in an open-source framework. Are you ok with us deleting the copyright?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lizbaron

This file was largely copied from a file in the project, as such, I preserved the license agreement that was in place.

The original file can be found here /Experiments/GenerateTestsForResultsetFilterDataTypes.sql


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
SET NOCOUNT ON;

CREATE TABLE #datatypes (example VARCHAR(MAX), datatype VARCHAR(MAX));
GO

INSERT INTO #datatypes (example, datatype) VALUES ('76456376', 'BIGINT')
INSERT INTO #datatypes (example, datatype) VALUES ('0x432643', 'BINARY(15)')
INSERT INTO #datatypes (example, datatype) VALUES ('1', 'BIT')
INSERT INTO #datatypes (example, datatype) VALUES ('ABCDEF', 'CHAR(15)')
INSERT INTO #datatypes (example, datatype) VALUES ('12/27/2010 11:54:12.003', 'DATETIME')
INSERT INTO #datatypes (example, datatype) VALUES ('234.567', 'DECIMAL(7,4)')
INSERT INTO #datatypes (example, datatype) VALUES ('12345.6789', 'FLOAT')
INSERT INTO #datatypes (example, datatype) VALUES ('XYZ', 'IMAGE')
INSERT INTO #datatypes (example, datatype) VALUES ('13', 'INT')
INSERT INTO #datatypes (example, datatype) VALUES ('12.95', 'MONEY')
INSERT INTO #datatypes (example, datatype) VALUES ('ABCDEF', 'NCHAR(15)')
INSERT INTO #datatypes (example, datatype) VALUES ('ABCDEF', 'NTEXT')
INSERT INTO #datatypes (example, datatype) VALUES ('345.67', 'NUMERIC(7,4)')
INSERT INTO #datatypes (example, datatype) VALUES ('ABCDEF', 'NVARCHAR(15)')
INSERT INTO #datatypes (example, datatype) VALUES ('ABCDEF', 'NVARCHAR(MAX)')
INSERT INTO #datatypes (example, datatype) VALUES ('12345.6789', 'REAL')
INSERT INTO #datatypes (example, datatype) VALUES ('12/27/2010 09:35', 'SMALLDATETIME')
INSERT INTO #datatypes (example, datatype) VALUES ('13', 'SMALLINT')
INSERT INTO #datatypes (example, datatype) VALUES ('13.95', 'SMALLMONEY')
INSERT INTO #datatypes (example, datatype) VALUES ('ABCDEF', 'SQL_VARIANT')
INSERT INTO #datatypes (example, datatype) VALUES ('ABCDEF', 'SYSNAME')
INSERT INTO #datatypes (example, datatype) VALUES ('ABCDEF', 'TEXT')
INSERT INTO #datatypes (example, datatype) VALUES ('0x1234', 'TIMESTAMP')
INSERT INTO #datatypes (example, datatype) VALUES ('7', 'TINYINT')
INSERT INTO #datatypes (example, datatype) VALUES ('F12AF25F-E043-4475-ADD1-96B8BBC6F16E', 'UNIQUEIDENTIFIER')
INSERT INTO #datatypes (example, datatype) VALUES ('ABCDEF', 'VARBINARY(15)')
INSERT INTO #datatypes (example, datatype) VALUES ('ABCDEF', 'VARBINARY(MAX)')
INSERT INTO #datatypes (example, datatype) VALUES ('ABCDEF', 'VARCHAR(15)')
INSERT INTO #datatypes (example, datatype) VALUES ('ABCDEF', 'VARCHAR(MAX)')
INSERT INTO #datatypes (example, datatype) VALUES ('<xml>hi</xml>', 'XML')


DECLARE @example VARCHAR(MAX), @datatype VARCHAR(MAX);
DECLARE recs CURSOR LOCAL FAST_FORWARD FOR
SELECT example, datatype
FROM #datatypes
ORDER BY datatype;

OPEN recs
FETCH NEXT FROM recs INTO @example, @datatype;

PRINT '-- GENERATED WITH tSQLt\Experiments\GenerateTestsForResultsetToTableDataTypes.sql';
PRINT 'CREATE PROC tSQLt_test_ResultSetToTable.[test ResultSetToTable can handle each datatype]';
PRINT 'AS';
PRINT 'BEGIN';

WHILE @@FETCH_STATUS = 0
BEGIN

PRINT ' EXEC tSQLt.AssertResultSetsHaveSameMetaData';
PRINT ' ''SELECT CAST(''''' + @example + ''''' AS ' + @datatype + ') AS val;'','
PRINT ' ''CREATE TABLE #Actual (val ' + @datatype + ' NULL); EXEC tSQLt.ResultSetToTable #Actual, 1, ''''SELECT CAST(''''''''' + @example + ''''''''' AS ' + @datatype + ') AS val;''''; SELECT * FROM #Actual;'';';

FETCH NEXT FROM recs INTO @example, @datatype;
END;

PRINT 'END;';
PRINT 'GO';
PRINT '';

CLOSE recs
DEALLOCATE recs
GO

DROP TABLE #datatypes;
5 changes: 5 additions & 0 deletions Source/tSQLtCLR_CreateProcs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ AS
EXTERNAL NAME tSQLtCLR.[tSQLtCLR.StoredProcedures].ResultSetFilter;
GO

CREATE PROCEDURE tSQLt.ResultSetToTable @targetTable NVARCHAR(MAX), @ResultsetNo INT, @Command NVARCHAR(MAX)
AS
EXTERNAL NAME tSQLtCLR.[tSQLtCLR.StoredProcedures].ResultSetToTable
GO

CREATE PROCEDURE tSQLt.AssertResultSetsHaveSameMetaData @expectedCommand NVARCHAR(MAX), @actualCommand NVARCHAR(MAX)
AS
EXTERNAL NAME tSQLtCLR.[tSQLtCLR.StoredProcedures].AssertResultSetsHaveSameMetaData;
Expand Down
8 changes: 7 additions & 1 deletion Tests/Tests.ssmssqlproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
</ConnectionNode>
</Items>
</Items>
</LogicalFolder>
<LogicalFolder Name="Queries" Type="0" Sorted="true">
<Items>
Expand Down Expand Up @@ -211,6 +211,12 @@
<AssociatedConnUserName />
<FullPath>Run_Methods_Tests.class.sql</FullPath>
</FileNode>
<FileNode Name="tSQLt_test_ResultSetToTable.class.sql">
<AssociatedConnectionMoniker />
<AssociatedConnSrvName />
<AssociatedConnUserName />
<FullPath>tSQLt_test_ResultSetToTable.class.sql</FullPath>
</FileNode>
<FileNode Name="StubRecordTests.class.sql">
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:Dev_tSQLt:True</AssociatedConnectionMoniker>
<AssociatedConnSrvName>Dev_tSQLt</AssociatedConnSrvName>
Expand Down
Loading