MySqlMariaChangesToDefaultBehavior - pengdows/pengdows.crud GitHub Wiki

Table of Contents

MySQL and MariaDB: Changes to Default Behavior

pengdows.crud applies a set of session-level overrides to ensure MySQL and MariaDB behave more like standards-compliant SQL engines and to prevent common forms of silent data corruption.

Session Settings Injected

SET SESSION sql_mode = 'STRICT_ALL_TABLES,ONLY_FULL_GROUP_BY,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION,ANSI_QUOTES';

These session settings are injected automatically when a connection is opened. They ensure:

SQL Mode Description Rationale
STRICT_ALL_TABLES Rejects invalid or out-of-range data on INSERT or UPDATE Prevents silent truncation or coercion of data
ONLY_FULL_GROUP_BY Enforces ANSI-compliant GROUP BY behavior Prevents ambiguous queries from executing with non-deterministic results
NO_ZERO_DATE Disallows use of '0000-00-00' as a date value Ensures proper coercion to .NET DateTime and avoids edge-case behavior
NO_ENGINE_SUBSTITUTION Fails if a requested engine is unavailable Prevents silent fallback to engines lacking key features (e.g., foreign keys)
ANSI_QUOTES Treats double quotes ("") as identifier quotes, not string literals Aligns MySQL/MariaDB with ANSI SQL behavior and other DB engines

Implications for Developers

  • These settings may cause legacy or loosely written queries to fail (intentionally)
  • They force explicitness and safety in your SQL and schema definitions
  • Queries and schema that run under these settings are far more portable across DB engines

Quote Handling

With ANSI_QUOTES enabled:

  • Use ' for string literals
  • Use " for object identifiers
This mirrors behavior in:
  • PostgreSQL
  • SQL Server (when QUOTED_IDENTIFIER ON)
  • Oracle

Known Compatibility Notes

  • If your schema or queries rely on non-strict behavior, you will need to update them.
  • You should review old migrations or third-party tooling for unsafe defaults.

Related Pages

⚠️ **GitHub.com Fallback** ⚠️