Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MariaDB Dialect Request #55

Closed
Conrad-T-Pino opened this issue Sep 7, 2024 · 4 comments · Fixed by #56
Closed

MariaDB Dialect Request #55

Conrad-T-Pino opened this issue Sep 7, 2024 · 4 comments · Fixed by #56

Comments

@Conrad-T-Pino
Copy link
Contributor

Table below excerpted from About MariaDB Connector/J § Infrequently Used Parameters

Parameter Description
useMysqlMetadata databaseMetaData.getDatabaseProductName() return "MariaDB" or "MySQL" according to server type (since 2.4.0). This option permit to force returning "MySQL" even if server is MariaDB to permit compatibility with frameworks that doesn't support MariaDB.
Default: false. Since 2.4.1

The latest MariaDB stable release is version 11.4 series.

  • I'd like to start by asking is this an easy thing or a hard thing?
  • If not too hard, I propose making this my first contribution.
@komu
Copy link
Member

komu commented Sep 9, 2024

It should be easy. First of all, most of the dialects do nothing special, e.g. MySQLDialect is just literally just:

public class MySQLDialect extends Dialect {
}

PostgreSQLDialect has some special code to support PostgreSQL's native enums and OracleDialect has workaround for array-handling, since Oracle's own JDBC driver does (or atleast did) not support the standard API.

So the actual dialect implementation would probably be empty just as MySQLDialect. And I should note that even without a custom implementation Dalesbred will work: it will just log a startup warning that it could not autodetect the database.

The actual detection logic is also straightforward:

public static @NotNull Dialect detect(@NotNull Connection connection) {
try {
String productName = connection.getMetaData().getDatabaseProductName();
switch (productName) {
case "PostgreSQL":
log.debug("Automatically detected dialect PostgreSQL.");
return new PostgreSQLDialect();
case "HSQL Database Engine":
log.debug("Automatically detected dialect HSQLDB.");
return new HsqldbDialect();
case "H2":
log.debug("Automatically detected dialect H2.");
return new H2Dialect();
case "MySQL":
log.debug("Automatically detected dialect MySQL.");
return new MySQLDialect();
case "Oracle":
log.debug("Automatically detected dialect Oracle.");
return new OracleDialect();
case "Microsoft SQL Server":
log.debug("Automatically detected dialect SQLServer.");
return new SQLServerDialect();
default:
log.info("Could not detect dialect for product name '{}', falling back to default.", productName);
return new DefaultDialect();
}
} catch (SQLException e) {
throw new DatabaseSQLException("Failed to auto-detect database dialect: " + e, e);
}
}

I don't believe that other changes are required.

@Conrad-T-Pino
Copy link
Contributor Author

Before first commit to Conrad-T-Pino / dalesbred branch MariaDB I thought a patch review might be useful but if that's not so, please advise what is best for the team.

patch-MariaDBDialect.txt

@komu
Copy link
Member

komu commented Sep 10, 2024

A pull request or a link to a commit is best. With Git you can always rewrite the commit history of a branch if there are cleanups to be made so even if the first commit has problems, it can be cleaned up before merging the branch. So the history of the mainline stays clean even if code needs to be rewritten before mergins.

That said, the patch looks fine so if you'll open a PR I'll merge it.

@Conrad-T-Pino
Copy link
Contributor Author

  • Did I say I'm not git expert?
  • Thank you for the guidance.
  • Pull Request 56 submitted.

@komu komu linked a pull request Sep 11, 2024 that will close this issue
@komu komu closed this as completed in #56 Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants