Fixed an exception when setting the SQL mode on non-MySQL-like databases.
authorMarco Zanon <info@marcozanon.com>
Wed, 28 Aug 2024 16:53:32 +0000 (16:53 +0000)
committerMarco Zanon <info@marcozanon.com>
Wed, 28 Aug 2024 16:53:32 +0000 (16:53 +0000)
10.x/CHANGELOG
10.x/src/main/java/com/marcozanon/macaco/databases/MDatabaseConnection.java

index 78d70a419edebf1b165be5f14a3fc3ef75a19ef9..41c4fe186ac468539c98b61d3863c3069d0210d3 100644 (file)
@@ -2,6 +2,11 @@ Macaco
 Copyright (c) 2009-2024 Marco Zanon <info@marcozanon.com>.
 See LICENSE for details.
 
+-------------------
+10.1.1 (2024-08-28)
+-------------------
+* Fixed an exception when setting the SQL mode on non-MySQL-like databases.
+
 -------------------
 10.1.0 (2024-07-28)
 -------------------
index a3e8f411ac9bba1a23670b4ac3bd94c24a23b9d8..fc611e2a754f35e3eeee13ffe06e4ec58a6883e6 100644 (file)
@@ -84,15 +84,17 @@ public class MDatabaseConnection extends MObject {
         catch (SQLException exception) {
             throw new MDatabaseConnectionFailureException("Could not get database connection.", exception);
         }
-        // Set SQL mode to standard ANSI and TRADITIONAL.
-        try {
-            this.getConnection().createStatement().executeUpdate("SET SQL_MODE = 'ANSI,TRADITIONAL'");
+        // Set SQL mode to standard ANSI and TRADITIONAL (MySQL / MariaDB databases only).
+        if (this.getDriver().toLowerCase().matches(".*(mysql|mariadb){1}.*")) {
+            try {
+                this.getConnection().createStatement().executeUpdate("SET SQL_MODE = 'ANSI,TRADITIONAL'");
 /* Disabled to prevent an infinite loop.
-            this.logStatement("### SET SQL_MODE = 'ANSI,TRADITIONAL' ###");
+                this.logStatement("### SET SQL_MODE = 'ANSI,TRADITIONAL' ###");
 */
-        }
-        catch (SQLException exception) {
-            throw new MDatabaseConnectionFailureException("Could not set SQL mode to ANSI and TRADITIONAL.", exception);
+            }
+            catch (SQLException exception) {
+                throw new MDatabaseConnectionFailureException("Could not set SQL mode to ANSI and TRADITIONAL.", exception);
+            }
         }
     }