Skip to content

Commit 056dc48

Browse files
committed
Replace DDL-driven definition of SQL Stored Procedures
1 parent 7e5a8b9 commit 056dc48

File tree

3 files changed

+22
-94
lines changed

3 files changed

+22
-94
lines changed

serverSide/src/vscode/dc/testingmanager/CoverageManager.cls

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,26 @@ ClassMethod RunTest(ByRef testspec As %String, qspec As %String, ByRef userparam
77
Return ##super(testspec, qspec, .userparam)
88
}
99

10+
ClassMethod tmInt8Bitstring(bitstring As %String) As %String [ SqlProc ]
11+
{
12+
Set output = "", iMod8=-1, char=0, weight=1
13+
For i=1:1:$BitCount(bitstring) {
14+
Set bitvalue = $Bit(bitstring, i)
15+
Set iMod8 = (i-1)#8
16+
If bitvalue {
17+
Set char = char+weight
18+
}
19+
Set weight = weight*2
20+
If iMod8 = 7 {
21+
Set output = output_$Char(char)
22+
Set char = 0, weight = 1
23+
Set iMod8 = -1
24+
}
25+
}
26+
If iMod8 > -1 {
27+
Set output = output_$Char(char)
28+
}
29+
Return output
30+
}
1031

1132
}

src/ourFileCoverage.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import logger from './logger';
33
import { IServerSpec } from '@intersystems-community/intersystems-servermanager';
44
import { makeRESTRequest } from './makeRESTRequest';
55
import { osAPI } from './extension';
6-
import { SQL_FN_INT8BITSTRING } from './utils';
76

87
export class OurFileCoverage extends vscode.FileCoverage {
98

@@ -89,7 +88,7 @@ export class OurFileCoverage extends vscode.FileCoverage {
8988
serverSpec,
9089
{ apiVersion: 1, namespace, path: "/action/query" },
9190
{
92-
query: `SELECT TestCoverage_UI.${SQL_FN_INT8BITSTRING}(cu.ExecutableLines) i8bsExecutableLines, TestCoverage_UI.${SQL_FN_INT8BITSTRING}(cov.CoveredLines) i8bsCoveredLines FROM TestCoverage_Data.CodeUnit cu, TestCoverage_Data.Coverage cov WHERE cu.Hash = cov.Hash AND Run = ? AND cu.Hash = ? AND TestPath = ?`,
91+
query: `SELECT vscode_dc_testingmanager.CoverageManager_tmInt8Bitstring(cu.ExecutableLines) i8bsExecutableLines, vscode_dc_testingmanager.CoverageManager_tmInt8Bitstring(cov.CoveredLines) i8bsCoveredLines FROM TestCoverage_Data.CodeUnit cu, TestCoverage_Data.Coverage cov WHERE cu.Hash = cov.Hash AND Run = ? AND cu.Hash = ? AND TestPath = ?`,
9392
parameters: [this.coverageIndex, this.codeUnit, testPath],
9493
},
9594
);

src/utils.ts

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ import { makeRESTRequest } from './makeRESTRequest';
44
import { IServerSpec } from '@intersystems-community/intersystems-servermanager';
55
import { osAPI } from './extension';
66

7-
const API_VERSION = 1; // Increment this whenever DDL of our util class changes
8-
export const UTIL_CLASSNAME = `TestCoverage.UI.VSCodeUtilsV${API_VERSION}`;
9-
export const SQL_FN_INT8BITSTRING = `fnVSCodeV${API_VERSION}Int8Bitstring`;
10-
export const SQL_FN_RUNTESTPROXY = `fnVSCodeV${API_VERSION}RunTestProxy`;
11-
127
export async function resolveServerSpecAndNamespace(uri: vscode.Uri): Promise<{ serverSpec: IServerSpec | undefined, namespace?: string }> {
138
const server = await osAPI.asyncServerForUri(uri);
149
if (!server) {
@@ -49,92 +44,5 @@ export async function supportsCoverage(folder: vscode.WorkspaceFolder): Promise<
4944
if (response?.status !== 200) {
5045
return false;
5146
}
52-
53-
// Does our util class already exist?
54-
response = await makeRESTRequest(
55-
"HEAD",
56-
serverSpec,
57-
{ apiVersion: 1, namespace, path: `/doc/${UTIL_CLASSNAME}.cls` }
58-
);
59-
if (response?.status === 200) {
60-
return true;
61-
}
62-
63-
// No, so create it
64-
return await createSQLUtilFunctions(serverSpec, namespace);
65-
}
66-
67-
async function createSQLUtilFunctions(serverSpec: IServerSpec, namespace: string): Promise<boolean> {
68-
logger.debug(`Creating our SQL Util functions class ${UTIL_CLASSNAME} for namespace: ${namespace}`);
69-
70-
const functionsAsDDL =[
71-
// Convert an InterSystems native bitstring to an 8-bit character bitstring for manipulation in Typescript.
72-
`
73-
CREATE FUNCTION ${SQL_FN_INT8BITSTRING}(
74-
bitstring VARCHAR(32767)
75-
)
76-
FOR ${UTIL_CLASSNAME}
77-
RETURNS VARCHAR(32767)
78-
LANGUAGE OBJECTSCRIPT
79-
{
80-
New output,iMod8,char,weight,i,bitvalue
81-
Set output = "", iMod8=-1, char=0, weight=1
82-
For i=1:1:$BitCount(bitstring) {
83-
Set bitvalue = $Bit(bitstring, i)
84-
Set iMod8 = (i-1)#8
85-
If bitvalue {
86-
Set char = char+weight
87-
}
88-
Set weight = weight*2
89-
If iMod8 = 7 {
90-
Set output = output_$Char(char)
91-
Set char = 0, weight = 1
92-
Set iMod8 = -1
93-
}
94-
}
95-
If iMod8 > -1 {
96-
Set output = output_$Char(char)
97-
}
98-
Quit output
99-
}
100-
`,
101-
// Create a proxy classmethod invoking TestCoverage.Manager.RunTest method with the "CoverageDetail" parameter.
102-
// Necessary because we run via the debugger so cannot directly pass by-reference the userparam array.
103-
`
104-
CREATE FUNCTION ${SQL_FN_RUNTESTPROXY}(
105-
testspec VARCHAR(32767),
106-
qspec VARCHAR(32767),
107-
coverageDetail INTEGER DEFAULT 1
108-
)
109-
FOR ${UTIL_CLASSNAME}
110-
RETURNS VARCHAR(32767)
111-
LANGUAGE OBJECTSCRIPT
112-
{
113-
New userparam
114-
Set userparam("CoverageDetail") = coverageDetail
115-
Quit ##class(TestCoverage.Manager).RunTest(
116-
testspec,
117-
qspec,
118-
.userparam
119-
)
120-
}
121-
`,
122-
];
123-
124-
for (const ddl of functionsAsDDL) {
125-
const response = await makeRESTRequest(
126-
"POST",
127-
serverSpec,
128-
{ apiVersion: 1, namespace, path: "/action/query" },
129-
{ query: ddl }
130-
);
131-
if (!response || response.status !== 200 || response.data?.status?.errors?.length) {
132-
vscode.window.showErrorMessage(
133-
`Failed to create SQL Util functions in namespace ${namespace}: ${response?.data?.status?.summary || 'Unknown error'}`,
134-
{ modal: true }
135-
);
136-
return false;
137-
}
138-
}
13947
return true;
14048
}

0 commit comments

Comments
 (0)