Skip to content

Commit cad6906

Browse files
HCK-13213: fix issue with replacing query statement with env vars and add query to error log (#59)
<!--do not remove this marker, its needed to replace info when ticket title is updated --> <!--jira-description-action-hidden-marker-start--> <table> <td> <a href="https://hackolade.atlassian.net/browse/HCK-13213" title="HCK-13213" target="_blank"><img alt="Sub-task" src="https://hackolade.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10316?size=medium" />HCK-13213</a> 1. Investigate incident </td></table> <br /> <!--jira-description-action-hidden-marker-end--> ## Content - Fixed an issue on Windows cmd.exe where parts of a query statement could be replaced by environment variables. - Added database version logging at the start of the connection process, before fetching the list of schemas. - Included the failed query (from the Java Db2 client) in error objects-now it's logged and visible in the extended error stack trace. - Simplified the Maven build configuration. ...
1 parent 1f03fa8 commit cad6906

8 files changed

Lines changed: 48 additions & 31 deletions

File tree

constants/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ const TABLE_TYPE = {
1313

1414
const INLINE_COMMENT = '--';
1515

16+
const PERSENT = '__PERCENT__';
17+
1618
module.exports = {
1719
ERROR_MESSAGE,
1820
TABLE_TYPE,
1921
INLINE_COMMENT,
22+
PERSENT,
2023
};

reverse_engineering/api.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,13 @@ const getDbCollectionsNames = async (connectionInfo, appLogger, callback, app) =
101101
});
102102

103103
try {
104+
const connection = await connectionHelper.connect({ connectionInfo, logger });
105+
const dbVersion = await instanceHelper.getDbVersion({ connection });
106+
logger.info('Db version: ' + dbVersion);
107+
104108
logger.info('Get table and schema names');
105109
logger.info(connectionInfo);
106110

107-
const connection = await connectionHelper.connect({ connectionInfo, logger });
108111
const tableNames = await instanceHelper.getDatabasesWithTableNames({
109112
connection,
110113
tableType: TABLE_TYPE.table,

shared/Db2Client/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
mvn clean compile assembly:single
3+
mvn clean package

shared/Db2Client/pom.xml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,29 @@
1818

1919
<build>
2020
<plugins>
21-
<plugin>
22-
<artifactId>maven-assembly-plugin</artifactId>
23-
<configuration>
24-
<archive>
25-
<manifest>
26-
<mainClass>org.db2.App</mainClass>
27-
</manifest>
28-
</archive>
29-
<descriptorRefs>
30-
<descriptorRef>jar-with-dependencies</descriptorRef>
31-
</descriptorRefs>
32-
</configuration>
33-
</plugin>
21+
<plugin>
22+
<artifactId>maven-assembly-plugin</artifactId>
23+
<version>3.7.1</version>
24+
<configuration>
25+
<archive>
26+
<manifest>
27+
<mainClass>org.db2.App</mainClass>
28+
</manifest>
29+
</archive>
30+
<descriptorRefs>
31+
<descriptorRef>jar-with-dependencies</descriptorRef>
32+
</descriptorRefs>
33+
</configuration>
34+
<executions>
35+
<execution>
36+
<id>make-assembly</id>
37+
<phase>package</phase>
38+
<goals>
39+
<goal>single</goal>
40+
</goals>
41+
</execution>
42+
</executions>
43+
</plugin>
3444
</plugins>
3545
</build>
3646

shared/Db2Client/readme.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,9 @@ For compiling client Using Maven plugin execute:
1919
Lifecycle methods:
2020

2121
- `mvn clean`
22-
- `mvn compile`
23-
24-
Plugins:
25-
26-
- `mvn assembly:single`
22+
- `mvn package`
2723

2824
### Built artifacts
2925

30-
The built JAR file you can find following by `./target/Db2Client-1.0-jar-with-dependencies.jar`
26+
The built JAR file you can find following by `./target/Db2Client-1.0-jar-with-dependencies.jar`, **NOT `Db2Client-1.0.jar`!!!**
3127
For use in Db2 plugin rename this JAR file to `Db2Client.jar` and put to `shared/addons/Db2Client.jar`

shared/Db2Client/src/main/java/org/db2/App.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public static void main(String[] args) {
3737
JSONObject errorObj = new JSONObject();
3838
errorObj.put("message", e.getMessage());
3939
errorObj.put("stack", e.getStackTrace());
40+
errorObj.put("query", query);
4041

4142
result.put("error", errorObj);
4243
} finally {
@@ -46,7 +47,7 @@ public static void main(String[] args) {
4647
}
4748

4849
private static String cleanStringValue(String value) {
49-
return value.replace("<\\$>", "\"");
50+
return value.replace("__PERCENT__", "%");
5051
}
5152

5253
private static String findArgument(String[] args, Argument argument) {

shared/addons/Db2Client.jar

1.18 KB
Binary file not shown.

shared/helpers/queryHelper.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { TABLE_TYPE } = require('../../constants/constants');
1+
const { TABLE_TYPE, PERSENT } = require('../../constants/constants');
22

33
/**
44
* @param {{ query: string }}
@@ -11,14 +11,18 @@ const cleanUpQuery = ({ query = '' }) => query.replaceAll(/\s+/g, ' ');
1111
* @returns {string}
1212
*/
1313
const getNonSystemSchemaWhereClause = ({ query, schemaNameKeyword }) => {
14-
const whereClause = `
15-
WHERE ${schemaNameKeyword} NOT LIKE 'SYS%'
16-
AND ${schemaNameKeyword} NOT LIKE '%SYSCAT%'
17-
AND ${schemaNameKeyword} NOT LIKE '%SYSIBM%'
18-
AND ${schemaNameKeyword} NOT LIKE '%SYSSTAT%'
19-
AND ${schemaNameKeyword} NOT LIKE '%SYSTOOLS%'
20-
AND ${schemaNameKeyword} NOT LIKE '%NULLID%'
21-
AND ${schemaNameKeyword} NOT LIKE '%SQLJ%';`;
14+
// On Windows (cmd.exe), environment variables can be referenced using syntax like %PATH%.
15+
// When a command contains such patterns, cmd.exe automatically replaces them with the corresponding environment variable values.
16+
// To prevent this automatic substitution, a placeholder string (PERSENT) is used here instead,
17+
// which will later be replaced with the % symbol inside the Db2Client Java client.
18+
const whereClause = `
19+
WHERE ${schemaNameKeyword} NOT LIKE 'SYS${PERSENT}'
20+
AND ${schemaNameKeyword} NOT LIKE '${PERSENT}SYSCAT${PERSENT}'
21+
AND ${schemaNameKeyword} NOT LIKE '${PERSENT}SYSIBM${PERSENT}'
22+
AND ${schemaNameKeyword} NOT LIKE '${PERSENT}SYSSTAT${PERSENT}'
23+
AND ${schemaNameKeyword} NOT LIKE '${PERSENT}SYSTOOLS${PERSENT}'
24+
AND ${schemaNameKeyword} NOT LIKE '${PERSENT}NULLID${PERSENT}'
25+
AND ${schemaNameKeyword} NOT LIKE '${PERSENT}SQLJ${PERSENT}';`;
2226

2327
const clause = query.includes('WHERE') ? whereClause.replace('WHERE', 'AND') : whereClause;
2428

0 commit comments

Comments
 (0)