Skip to content

fix: correct SQL string escaping for MySQL, InterBase, Firebird and Access#8

Open
vipitec-neo wants to merge 1 commit intohickelsoft:mainfrom
vipitec-neo:fix/sql-escape-string-order
Open

fix: correct SQL string escaping for MySQL, InterBase, Firebird and Access#8
vipitec-neo wants to merge 1 commit intohickelsoft:mainfrom
vipitec-neo:fix/sql-escape-string-order

Conversation

@vipitec-neo
Copy link

@vipitec-neo vipitec-neo commented Feb 10, 2026

Problem

SQL_Escape_String in C_Database.pas had two bugs:

1. MySQL: Wrong escaping order

Backslash and quote escaping were in the wrong order, causing double-escaping:

  • Input: O'Brien
  • After '\': O\'Brien
  • After \\\: O\\'Brien ← broken!

2. InterBase, Firebird, Access: Wrong escaping method

These DBMS use SQL-standard '' escaping, not MySQL-style \'. The old code produced invalid SQL.

Fix

  • MySQL: Escape \ first, then ' (correct order)
  • InterBase/Firebird/Access: Use '' (SQL standard) instead of \'

Tests

Unit Tests (Free Pascal)

9 tests verifying the escaping functions in isolation. Compiled with fpc.

Integration Tests (Docker)

7 tests against real database engines:

  • Firebird 4.0: '' works ✅, \' rejected ✅, backslash literal works ✅
  • MariaDB 10: \' works ✅, \\ needed for backslash ✅, unescaped \ swallowed ✅, double-escaping bug confirmed ✅

Not tested (no Docker images available)

  • InterBase: Proprietary (Embarcadero). Shares SQL dialect with Firebird (its open-source fork), so '' escaping is identical.
  • Access: Windows-only file-based DB (Jet/ACE). Uses SQL-standard '' escaping per Microsoft docs.
  • BDE/Paradox/dBase: Legacy 32-bit only, no Docker option.

CI

GitHub Actions workflow included — runs both unit and integration tests automatically.

@vipitec-neo vipitec-neo force-pushed the fix/sql-escape-string-order branch 4 times, most recently from 47aa520 to 259d071 Compare February 10, 2026 21:24
…ccess

SQL_Escape_String had two bugs:

1. MySQL: backslash and quote escaping were in the wrong order.
   Input O'Brien -> O\'Brien -> O\\'Brien (double-escaped).
   Fix: escape backslashes first, then quotes.

2. InterBase, Firebird, Access: these DBMS use SQL-standard
   double-quote escaping (''), not backslash escaping (\').
   Using backslash escaping produced invalid SQL on these engines.

SQL Server escaping (double-quote style) was already correct.
@vipitec-neo vipitec-neo force-pushed the fix/sql-escape-string-order branch from 259d071 to daeb519 Compare February 10, 2026 21:54
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 this pull request may close these issues.

1 participant