Skip to content

Commit dc0aef5

Browse files
committed
Added CMD_PRINT_ALL_LINES and CMD_BUILD_SCRIPTS
1 parent ea43675 commit dc0aef5

File tree

4 files changed

+220
-3
lines changed

4 files changed

+220
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
CREATE PROCEDURE T4SQL.CMD_BUILD_SCRIPTS
2+
(
3+
@inWorkitem_Table NVARCHAR(128),
4+
@inSearch_Conditions NVARCHAR(4000),
5+
@outGenerated_Scripts NVARCHAR(MAX)
6+
)
7+
AS
8+
SET NOCOUNT ON
9+
10+
IF OBJECT_ID(@inWorkitem_Table, N'U') IS NULL
11+
BEGIN
12+
SET @outGenerated_Scripts = N'------ Invalid table name ''' + @inWorkitem_Table + N''' (@inWorkitem_Table) ------';
13+
PRINT @outGenerated_Scripts;
14+
RETURN -1;
15+
END;
16+
17+
CREATE TABLE #WORKITEMS (ROW_INDEX INT PRIMARY KEY, WORKITEM_NAME NVARCHAR(32));
18+
19+
DECLARE @tCnt INT, @tSQL NVARCHAR(2000);
20+
21+
SET @tSQL = N'SELECT ROW_NUMBER() OVER (ORDER BY ISNULL(BUILD_ORDER, 999999999), WORKITEM_NAME) AS ROW_INDEX, WORKITEM_NAME FROM ' + @inWorkitem_Table;
22+
23+
IF LEN(@inSearch_Conditions) > 1
24+
SET @tSQL += N' WHERE ' + @inSearch_Conditions;
25+
26+
SET @tSQL += N' ORDER BY ISNULL(BUILD_ORDER, 999999999), WORKITEM_NAME';
27+
28+
INSERT INTO #WORKITEMS (ROW_INDEX, WORKITEM_NAME)
29+
EXECUTE sp_executesql @tSQL;
30+
31+
SET @tCnt = @@ROWCOUNT;
32+
33+
IF @tCnt = 0
34+
BEGIN
35+
SET @outGenerated_Scripts = N'------------------ None workitem to build ------------------';
36+
PRINT @outGenerated_Scripts;
37+
RETURN 0;
38+
END;
39+
40+
SET @tSQL = N'UPDATE ' + @inWorkitem_Table + N' SET START_BUILD = 1 WHERE START_BUILD = 0';
41+
42+
IF LEN(@inSearch_Conditions) > 1
43+
SET @tSQL += N' AND (' + @inSearch_Conditions + N')';
44+
45+
EXECUTE sp_executesql @tSQL; -- Start building
46+
47+
WAITFOR DELAY '00:00:06';
48+
49+
DECLARE @tI INT, @tAttempts INT, @tWorkitem_Name NVARCHAR(32), @tParmDef NVARCHAR(512);
50+
DECLARE @tStart_Build BIT, @tObject_Code NVARCHAR(MAX), @tCompiled_Error NVARCHAR(2000);
51+
52+
SET @tSQL = N'SELECT @outStart_Build = START_BUILD, @outObject_Code = OBJECT_CODE, @outCompiled_Error = COMPILED_ERROR FROM '
53+
+ @inWorkitem_Table + N' WHERE WORKITEM_NAME = @inWorkitem_Name';
54+
SET @tParmDef = N'@inWorkitem_Name NVARCHAR(32), @outStart_Build BIT OUTPUT, @outObject_Code NVARCHAR(MAX) OUTPUT, @outCompiled_Error NVARCHAR(2000) OUTPUT';
55+
SET @outGenerated_Scripts = N'';
56+
SET @tI = 1;
57+
58+
WHILE @tI <= @tCnt
59+
BEGIN
60+
SELECT @tWorkitem_Name = WORKITEM_NAME FROM #WORKITEMS WHERE ROW_INDEX = @tI;
61+
62+
SET @outGenerated_Scripts += N'
63+
------------------ Build started workitem: ' + @tWorkitem_Name + N' ------------------
64+
';
65+
SET @tAttempts = 60;
66+
67+
WHILE 1 = 1
68+
BEGIN
69+
SET @tStart_Build = NULL;
70+
SET @tObject_Code = NULL;
71+
SET @tCompiled_Error = NULL;
72+
73+
EXECUTE sp_executesql @tSQL, @tParmDef,
74+
@tWorkitem_Name,
75+
@tStart_Build OUTPUT,
76+
@tObject_Code OUTPUT,
77+
@tCompiled_Error OUTPUT;
78+
IF @tStart_Build = 1
79+
BEGIN
80+
IF @tAttempts > 0 -- Retry
81+
BEGIN
82+
WAITFOR DELAY '00:00:03';
83+
SET @tAttempts -= 1;
84+
END
85+
ELSE
86+
BREAK;
87+
END
88+
ELSE
89+
BREAK;
90+
END;
91+
92+
IF @tStart_Build IS NULL
93+
BEGIN
94+
SET @outGenerated_Scripts += N'
95+
------------------ Error: The workitem has been deleted by others ------------------
96+
';
97+
CONTINUE;
98+
END
99+
ELSE IF @tStart_Build = 1
100+
BEGIN
101+
SET @outGenerated_Scripts += N'
102+
------------------ Error: Template Engine is down ------------------
103+
';
104+
BREAK;
105+
END;
106+
107+
IF @tCompiled_Error IS NULL OR @tCompiled_Error = N''
108+
SET @outGenerated_Scripts += @tObject_Code;
109+
ELSE
110+
SET @outGenerated_Scripts += N'/*
111+
' + @tCompiled_Error + N'
112+
*/';
113+
114+
SET @outGenerated_Scripts += N'
115+
------------------ Build ended workitem: ' + @tWorkitem_Name + N' ------------------
116+
';
117+
SET @tI += 1;
118+
END;
119+
120+
SET @outGenerated_Scripts += N'
121+
------------------ Build Total: ' + CAST(@tCnt AS NVARCHAR(8)) + N' Workitems ------------------';
122+
123+
EXEC T4SQL.CMD_PRINT_ALL_LINES @outGenerated_Scripts;
124+
125+
----------------------------------------------------------------------------------------------------
126+
--
127+
-- Copyright 2013 Abel Cheng
128+
-- This source code is subject to terms and conditions of the Apache License, Version 2.0.
129+
-- See http://www.apache.org/licenses/LICENSE-2.0.
130+
-- All other rights reserved.
131+
-- You must not remove this notice, or any other, from this software.
132+
--
133+
-- Original Author: Abel Cheng <[email protected]>
134+
-- Created Date: ‎June ‎20, ‎2013, ‏‎11:41:44 PM
135+
-- Primary Host: http://t4sql.codeplex.com
136+
-- Change Log:
137+
-- Author Date Comment
138+
--
139+
--
140+
--
141+
--
142+
-- (Keep code clean)
143+
--
144+
----------------------------------------------------------------------------------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
CREATE PROCEDURE T4SQL.CMD_PRINT_ALL_LINES
2+
(
3+
@inMessage NVARCHAR(MAX)
4+
)
5+
AS
6+
SET NOCOUNT ON
7+
8+
IF @inMessage IS NULL OR @inMessage = N''
9+
RETURN;
10+
11+
DECLARE @tNewLine NVARCHAR(3), @tNL INT;
12+
13+
SET @tNewLine = N'
14+
';
15+
SET @tNL = LEN(@tNewLine);
16+
17+
DECLARE @tSegLen INT, @tTextLen INT, @tStart INT, @tEnd INT;
18+
19+
SET @tSegLen = 3000;
20+
SET @tTextLen = LEN(@inMessage);
21+
SET @tStart = 1;
22+
23+
WHILE 1 = 1
24+
BEGIN
25+
SET @tEnd = @tStart + @tSegLen
26+
27+
IF @tEnd < @tTextLen
28+
BEGIN
29+
SET @tEnd = CHARINDEX(@tNewLine, @inMessage, @tEnd);
30+
IF @tEnd > 0
31+
BEGIN
32+
PRINT SUBSTRING(@inMessage, @tStart, @tEnd - @tStart);
33+
SET @tStart = @tEnd + @tNL;
34+
CONTINUE;
35+
END
36+
END;
37+
38+
PRINT SUBSTRING(@inMessage, @tStart, @tTextLen - @tStart + 1);
39+
BREAK;
40+
END;
41+
42+
----------------------------------------------------------------------------------------------------
43+
--
44+
-- Copyright 2013 Abel Cheng
45+
-- This source code is subject to terms and conditions of the Apache License, Version 2.0.
46+
-- See http://www.apache.org/licenses/LICENSE-2.0.
47+
-- All other rights reserved.
48+
-- You must not remove this notice, or any other, from this software.
49+
--
50+
-- Original Author: Abel Cheng <[email protected]>
51+
-- Created Date: June ‎23, ‎2013, ‏‎11:24:38 PM
52+
-- Primary Host: http://t4sql.codeplex.com
53+
-- Change Log:
54+
-- Author Date Comment
55+
--
56+
--
57+
--
58+
--
59+
-- (Keep code clean)
60+
--
61+
----------------------------------------------------------------------------------------------------

T4SQLTemplateLibrary/Databases/SqlServer/T4SQLDB.sqlproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
<OutputType>Database</OutputType>
2323
<RootPath>
2424
</RootPath>
25-
<IncludeSchemaNameInFileName>False</IncludeSchemaNameInFileName>
25+
<IncludeSchemaNameInFileName>True</IncludeSchemaNameInFileName>
2626
<ModelCollation>1033,CI</ModelCollation>
2727
<DefaultFileStructure>BySchemaAndSchemaType</DefaultFileStructure>
2828
<LoadSqlClrTypes>True</LoadSqlClrTypes>
2929
<RootNamespace>T4SQL</RootNamespace>
30-
<DefaultSchema>dbo</DefaultSchema>
30+
<DefaultSchema>T4SQL</DefaultSchema>
3131
<PreviousProjectVersion>4.0</PreviousProjectVersion>
3232
<SccProjectName>SAK</SccProjectName>
3333
<SccProvider>SAK</SccProvider>
@@ -37,7 +37,7 @@
3737
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
3838
<ProjectGuid>{7deafca2-b40a-4c8b-a6bb-8123bdf91ab4}</ProjectGuid>
3939
<GenerateDatabaseFile>False</GenerateDatabaseFile>
40-
<GenerateCreateScript>False</GenerateCreateScript>
40+
<GenerateCreateScript>True</GenerateCreateScript>
4141
<SqlServerVerification>False</SqlServerVerification>
4242
<TargetLanguage>CS</TargetLanguage>
4343
<DefaultCollation>SQL_Latin1_General_CP1_CI_AS</DefaultCollation>
@@ -303,6 +303,8 @@
303303
<Build Include="Schema Objects\Schemas\T4SQL\Programmability\Stored Procedures\T4SQL.ENGINE_GET_DB_SERVER_ENV.proc.sql">
304304
<SubType>Code</SubType>
305305
</Build>
306+
<Build Include="Schema Objects\Schemas\T4SQL\Programmability\Stored Procedures\T4SQL.CMD_BUILD_SCRIPTS.sql" />
307+
<Build Include="Schema Objects\Schemas\T4SQL\Programmability\Stored Procedures\T4SQL.CMD_PRINT_ALL_LINES.sql" />
306308
</ItemGroup>
307309
<ItemGroup>
308310
<None Include="Scripts\Post-Deployment\1-T4SQL.ENGINE_CONFIG.data.sql">
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
""
2+
{
3+
"FILE_VERSION" = "9237"
4+
"ENLISTMENT_CHOICE" = "NEVER"
5+
"PROJECT_FILE_RELATIVE_PATH" = ""
6+
"NUMBER_OF_EXCLUDED_FILES" = "0"
7+
"ORIGINAL_PROJECT_FILE_PATH" = ""
8+
"NUMBER_OF_NESTED_PROJECTS" = "0"
9+
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
10+
}

0 commit comments

Comments
 (0)