From ad95f8c64fe073367c5048dfa85d9769b50be347 Mon Sep 17 00:00:00 2001 From: ThuF Date: Thu, 28 Jan 2021 16:01:15 +0200 Subject: [PATCH 1/2] #692 SQL DeleteBuilder Fixes --- .../sql/builders/AbstractSqlBuilder.java | 9 +- .../sql/builders/records/DeleteBuilder.java | 6 +- .../sql/dialects/DefaultSqlDialect.java | 1 + .../sql/dialects/h2/H2SqlDialect.java | 21 ++- .../sql/dialects/hana/HanaSqlDialect.java | 1 + .../sql/dialects/mysql/MySQLSqlDialect.java | 3 +- .../dialects/postgres/PostgresSqlDialect.java | 15 ++- .../sql/dialects/sybase/SybaseSqlDialect.java | 22 ++- .../database/sql/test/CreateTableTest.java | 27 +++- .../database/sql/test/CreateViewTest.java | 27 +++- .../database/sql/test/DeleteTest.java | 24 +++- .../database/sql/test/DropTableTest.java | 26 +++- .../database/sql/test/DropViewTest.java | 20 ++- .../database/sql/test/InsertTest.java | 73 +++++++++- .../database/sql/test/SequenceTest.java | 64 ++++++++- .../database/sql/test/UpdateTest.java | 125 ++++++++++++++++-- 16 files changed, 421 insertions(+), 43 deletions(-) diff --git a/modules/database/database-sql/src/main/java/org/eclipse/dirigible/database/sql/builders/AbstractSqlBuilder.java b/modules/database/database-sql/src/main/java/org/eclipse/dirigible/database/sql/builders/AbstractSqlBuilder.java index 2a4928fb398..1b6196f39ea 100644 --- a/modules/database/database-sql/src/main/java/org/eclipse/dirigible/database/sql/builders/AbstractSqlBuilder.java +++ b/modules/database/database-sql/src/main/java/org/eclipse/dirigible/database/sql/builders/AbstractSqlBuilder.java @@ -120,7 +120,7 @@ protected String encapsulateMany(String line) { String[] words = line.split(regex); Set functionsNames = getDialect().getFunctionsNames(); for (String word : words) { - if (isNumeric(word)) { + if (isNumeric(word) || isValue(word)) { continue; } if (!"".equals(word.trim()) @@ -144,4 +144,11 @@ protected boolean isNumeric(String s) { } return numericPattern.matcher(s).matches(); } + + protected boolean isValue(String s) { + if (s == null) { + return false; + } + return s.startsWith("'") || s.endsWith("'"); + } } diff --git a/modules/database/database-sql/src/main/java/org/eclipse/dirigible/database/sql/builders/records/DeleteBuilder.java b/modules/database/database-sql/src/main/java/org/eclipse/dirigible/database/sql/builders/records/DeleteBuilder.java index 40cd09222ad..85978b52aea 100644 --- a/modules/database/database-sql/src/main/java/org/eclipse/dirigible/database/sql/builders/records/DeleteBuilder.java +++ b/modules/database/database-sql/src/main/java/org/eclipse/dirigible/database/sql/builders/records/DeleteBuilder.java @@ -1,12 +1,12 @@ /* - * Copyright (c) 2010-2020 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors + * Copyright (c) 2010-2021 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v20.html * - * SPDX-FileCopyrightText: 2010-2020 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors + * SPDX-FileCopyrightText: 2010-2021 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors * SPDX-License-Identifier: EPL-2.0 */ package org.eclipse.dirigible.database.sql.builders.records; @@ -98,7 +98,7 @@ public String generate() { */ protected void generateTable(StringBuilder sql) { String tableName = (isCaseSensitive()) ? encapsulate(this.getTable()) : this.getTable(); - sql.append(SPACE).append(KEYWORD_FROM).append(SPACE).append(this.table); + sql.append(SPACE).append(KEYWORD_FROM).append(SPACE).append(tableName); } /** diff --git a/modules/database/database-sql/src/main/java/org/eclipse/dirigible/database/sql/dialects/DefaultSqlDialect.java b/modules/database/database-sql/src/main/java/org/eclipse/dirigible/database/sql/dialects/DefaultSqlDialect.java index 3f85b1993e5..57c3853a353 100644 --- a/modules/database/database-sql/src/main/java/org/eclipse/dirigible/database/sql/dialects/DefaultSqlDialect.java +++ b/modules/database/database-sql/src/main/java/org/eclipse/dirigible/database/sql/dialects/DefaultSqlDialect.java @@ -203,6 +203,7 @@ public class DefaultSqlDialect