Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,28 @@ public interface DdlGenerator extends IdentifierQuoter, DialectCapabilitiesProvi

/**
* @param ifExists whether to include IF NOT EXISTS clause
* @return SQL statement to create the schema
* @return SQL statement to create the schema, {@code null} where the database has no schemas to create
* ({@link #supportsSchemas()} is false)
*/
String createSchema(String schemaName, boolean ifExists);

/**
* @param ifExists whether to include IF EXISTS clause
* @param cascade whether to include CASCADE clause
* @return SQL statement to drop the schema
* @return SQL statement to drop the schema, {@code null} where the database has no schemas to drop
* ({@link #supportsSchemas()} is false)
*/
String dropSchema(String schemaName, boolean ifExists, boolean cascade);

/**
* @return true if {@code createSchema} / {@code dropSchema} render statements: the database keeps schemas, name
* spaces of tables inside one database, created and dropped by SQL. SQLite has none: its schemas are the
* database files attached to a connection, and it refuses {@code CREATE SCHEMA}.
*/
default boolean supportsSchemas() {
return true;
}

// -------------------- DDL — descriptor-based --------------------

default String createTable(TableReference table, List<ColumnDefinition> columns, PrimaryKey primaryKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2026 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.daanse.sql.dialect.db.consistencytest;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.stream.Stream;

import org.eclipse.daanse.sql.dialect.api.Dialect;
import org.eclipse.daanse.sql.dialect.api.generator.DdlGenerator;
import org.eclipse.daanse.sql.dialect.db.clickhouse.ClickHouseDialect;
import org.eclipse.daanse.sql.dialect.db.common.AnsiDialect;
import org.eclipse.daanse.sql.dialect.db.derby.DerbyDialect;
import org.eclipse.daanse.sql.dialect.db.duckdb.DuckDbDialect;
import org.eclipse.daanse.sql.dialect.db.h2.H2Dialect;
import org.eclipse.daanse.sql.dialect.db.hive.HiveDialect;
import org.eclipse.daanse.sql.dialect.db.impala.ImpalaDialect;
import org.eclipse.daanse.sql.dialect.db.mariadb.MariaDBDialect;
import org.eclipse.daanse.sql.dialect.db.mssqlserver.MicrosoftSqlServerDialect;
import org.eclipse.daanse.sql.dialect.db.mysql.MySqlDialect;
import org.eclipse.daanse.sql.dialect.db.oracle.OracleDialect;
import org.eclipse.daanse.sql.dialect.db.postgresql.PostgreSqlDialect;
import org.eclipse.daanse.sql.dialect.db.sqlite.SqliteDialect;
import org.junit.jupiter.api.Named;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

/**
* Which dialect has schemas to create and drop: {@link DdlGenerator#supportsSchemas()}, and a statement from
* {@code createSchema} and {@code dropSchema} where it says yes, none where it says no. SQLite alone has no schemas
* inside a database. What the statements of the others say is left to the tests of each dialect.
*/
class SchemaStatementsTest {

static Stream<Arguments> dialects() {
return Stream.of(of("postgresql", new PostgreSqlDialect(), true), of("h2", new H2Dialect(), true),
of("duckdb", new DuckDbDialect(), true), of("ansi", new AnsiDialect(), true),
of("oracle", new OracleDialect(), true), of("mssql", new MicrosoftSqlServerDialect(), true),
of("mysql", new MySqlDialect(), true), of("mariadb", new MariaDBDialect(), true),
of("clickhouse", new ClickHouseDialect(), true), of("hive", new HiveDialect(), true),
of("impala", new ImpalaDialect(), true), of("derby", new DerbyDialect(), true),
of("sqlite", new SqliteDialect(), false));
}

@ParameterizedTest(name = "{0}")
@MethodSource("dialects")
void createsAndDropsASchema(Dialect dialect, boolean schemas) {
DdlGenerator ddl = dialect.ddlGenerator();
assertThat(ddl.supportsSchemas()).as("supportsSchemas").isEqualTo(schemas);
if (schemas) {
assertThat(ddl.createSchema("s", true)).as("createSchema").isNotBlank();
assertThat(ddl.dropSchema("s", true, true)).as("dropSchema").isNotBlank();
} else {
assertThat(ddl.createSchema("s", true)).as("no createSchema").isNull();
assertThat(ddl.dropSchema("s", true, true)).as("no dropSchema").isNull();
}
}

private static Arguments of(String name, Dialect dialect, boolean schemas) {
return Arguments.of(Named.of(name, dialect), schemas);
}
}
13 changes: 13 additions & 0 deletions dialect/db/sqlite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@
<version>3.45.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.daanse</groupId>
<artifactId>org.eclipse.daanse.sql.jdbc.record</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<!-- Container tests: the sqlite3 CLI of a given version, run in Docker. -->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.21.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.daanse</groupId>
<artifactId>org.eclipse.daanse.sql.dialect.db.test-support</artifactId>
Expand Down
Loading
Loading