Skip to content

Commit d6ed1c7

Browse files
author
Olha Virolainen
authored
Merge pull request #12 from elasticio/issue-195-unknown-table-error
define catalog for mysql (getPrimaryKeys method)
2 parents 0dbbf19 + f1e4351 commit d6ed1c7

File tree

6 files changed

+33
-12
lines changed

6 files changed

+33
-12
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ The format of ``Start Polling From (optional)`` field should be like ``yyyy-mm-d
108108
- ``ss`` - second
109109
- ``sss`` - millisecond (optional)
110110

111+
*Please Note: Component Snapshot will not be overwritten in Real-Time flows due to platform behaviour, so we strongly recommend to use Get Rows Polling trigger in Keen Flows only*
112+
111113
### SELECT trigger (Deprecated)
112114
This action exists in JDBC component only for backward compatibility. New [**Select trigger**](#select-trigger) is recommended to use.
113115

@@ -216,9 +218,6 @@ This action exists in JDBC component only for backward compatibility. [**Upsert
216218
- ``MSSQL`` - compatible with Microsoft SQL Server 2008 R2 and higher
217219
3. The current implementation of the action ``Upsert By Primary Key`` doesn't mark non-nullable fields as required fields at a dynamic metadata. In case of updating such fields with an empty value you will get SQL Exception ``Cannot insert the value NULL into...``. You should manually fill in all non-nullable fields with previous data, if you want to update part of columns in a row, even if data in that fields doesn't change.
218220

219-
## Known issues
220-
No known issues are there yet.
221-
222221
## License
223222
Apache-2.0 © [elastic.io GmbH](https://www.elastic.io "elastic.io GmbH")
224223

component.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"title": "Database MySQL",
2+
"title": "Database",
33
"description": "Database JDBC connector",
44
"credentials": {
55
"verifier": "io.elastic.jdbc.JdbcCredentialsVerifier",
@@ -105,8 +105,9 @@
105105
},
106106
"select": {
107107
"main": "io.elastic.jdbc.triggers.SelectTriggerOld",
108-
"title": "SELECT (Deprecated)",
109-
"description": "This trigger is already deprecated. Please use 'Select' trigger",
108+
"title": "SELECT",
109+
"deprecated": true,
110+
"description": "DEPRECATED: Please use 'Select' Trigger",
110111
"type": "polling",
111112
"fields": {
112113
"tableName": {
@@ -206,7 +207,9 @@
206207
},
207208
"createOrUpdateRecord": {
208209
"main": "io.elastic.jdbc.actions.CreateOrUpdateRecord",
209-
"title": "Create or update record (Deprecated)",
210+
"title": "Create or update record",
211+
"deprecated": true,
212+
"description": "DEPRECATED: Please use 'Upsert Row By Primary Key' Action",
210213
"fields": {
211214
"tableName": {
212215
"viewClass": "SelectView",

src/main/java/io/elastic/jdbc/ColumnNamesProvider.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,18 @@ public JsonObject getColumns(JsonObject configuration) {
5555
JsonObjectBuilder properties = Json.createObjectBuilder();
5656
Connection connection = null;
5757
ResultSet rs = null;
58+
String catalog = null;
5859
String schemaName = null;
5960
boolean isEmpty = true;
60-
Boolean isOracle = configuration.getString("dbEngine").equals("oracle");
6161
Boolean isMssql = configuration.getString("dbEngine").equals("mssql");
62+
Boolean isMysql = configuration.getString("dbEngine").equals("mysql");
6263
try {
6364
connection = Utils.getConnection(configuration);
6465
DatabaseMetaData dbMetaData = connection.getMetaData();
65-
rs = dbMetaData.getPrimaryKeys(null, null, tableName);
66+
if (isMysql) {
67+
catalog = configuration.getString("databaseName");
68+
}
69+
rs = dbMetaData.getPrimaryKeys(catalog, null, tableName);
6670
if (tableName.contains(".")) {
6771
schemaName = tableName.split("\\.")[0];
6872
tableName = tableName.split("\\.")[1];

src/main/java/io/elastic/jdbc/ColumnNamesWithPrimaryKeyProvider.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,23 @@ public JsonObject getColumns(JsonObject configuration) {
5757
Connection connection = null;
5858
ResultSet rs = null;
5959
ResultSet rsPrimaryKeys = null;
60+
String catalog = null;
6061
String schemaName = null;
6162
boolean isEmpty = true;
6263
Boolean isOracle = configuration.getString("dbEngine").equals("oracle");
64+
Boolean isMysql = configuration.getString("dbEngine").equals("mysql");
6365
try {
6466
connection = Utils.getConnection(configuration);
6567
DatabaseMetaData dbMetaData = connection.getMetaData();
6668
if (tableName.contains(".")) {
6769
schemaName = tableName.split("\\.")[0];
6870
tableName = tableName.split("\\.")[1];
6971
}
72+
if (isMysql) {
73+
catalog = configuration.getString("databaseName");
74+
}
7075
rsPrimaryKeys = dbMetaData
71-
.getPrimaryKeys(null, ((isOracle && !schemaName.isEmpty()) ? schemaName : null),
76+
.getPrimaryKeys(catalog, ((isOracle && !schemaName.isEmpty()) ? schemaName : null),
7277
tableName);
7378
rs = dbMetaData.getColumns(null, schemaName, tableName, "%");
7479
while (rs.next()) {

src/main/java/io/elastic/jdbc/PrimaryColumnNamesProvider.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,27 @@ public JsonObject getPrimaryColumns(JsonObject configuration) {
5555
JsonObject properties = Json.createObjectBuilder().build();
5656
Connection connection = null;
5757
ResultSet rs = null;
58+
String catalog = null;
5859
String schemaName = null;
5960
Boolean isEmpty = true;
6061
Boolean isOracle = configuration.getString("dbEngine").equals("oracle");
6162
Boolean isMssql = configuration.getString("dbEngine").equals("mssql");
63+
Boolean isMysql = configuration.getString("dbEngine").equals("mysql");
6264
List<String> primaryKeys = new ArrayList();
6365
try {
6466
connection = Utils.getConnection(configuration);
6567
DatabaseMetaData dbMetaData = connection.getMetaData();
68+
if (isMysql) {
69+
catalog = configuration.getString("databaseName");
70+
}
6671
if (tableName.contains(".")) {
6772
schemaName =
6873
(isOracle) ? tableName.split("\\.")[0].toUpperCase() : tableName.split("\\.")[0];
6974
tableName =
7075
(isOracle) ? tableName.split("\\.")[1].toUpperCase() : tableName.split("\\.")[1];
7176
}
7277
rs = dbMetaData
73-
.getPrimaryKeys(null, ((isOracle && !schemaName.isEmpty()) ? schemaName : null),
78+
.getPrimaryKeys(catalog, ((isOracle && !schemaName.isEmpty()) ? schemaName : null),
7479
tableName);
7580
while (rs.next()) {
7681
primaryKeys.add(rs.getString("COLUMN_NAME"));

src/main/java/io/elastic/jdbc/actions/UpsertRowByPrimaryKey.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public void execute(ExecutionParameters parameters) {
3030
JsonObject resultRow;
3131
String tableName;
3232
String dbEngine;
33+
String catalog = null;
3334
String schemaName = "";
3435
String primaryKey = "";
3536
int primaryKeysCount = 0;
@@ -54,17 +55,21 @@ public void execute(ExecutionParameters parameters) {
5455

5556
LOGGER.info("Executing lookup primary key");
5657
boolean isOracle = dbEngine.equals(Engines.ORACLE.name().toLowerCase());
58+
Boolean isMysql = configuration.getString("dbEngine").equals("mysql");
5759

5860
try (Connection connection = Utils.getConnection(configuration)) {
5961
DatabaseMetaData dbMetaData = connection.getMetaData();
62+
if (isMysql) {
63+
catalog = configuration.getString("databaseName");
64+
}
6065
if (tableName.contains(".")) {
6166
schemaName =
6267
(isOracle) ? tableName.split("\\.")[0].toUpperCase() : tableName.split("\\.")[0];
6368
tableName =
6469
(isOracle) ? tableName.split("\\.")[1].toUpperCase() : tableName.split("\\.")[1];
6570
}
6671
try (ResultSet rs = dbMetaData
67-
.getPrimaryKeys(null, ((isOracle && !schemaName.isEmpty()) ? schemaName : null),
72+
.getPrimaryKeys(catalog, ((isOracle && !schemaName.isEmpty()) ? schemaName : null),
6873
tableName)) {
6974
while (rs.next()) {
7075
primaryKey = rs.getString("COLUMN_NAME");

0 commit comments

Comments
 (0)