Skip to content

db: make floatToSql() a public static helper on DB - #16

Merged
daveedis merged 2 commits into
mainfrom
float-to-sql-public
Sep 5, 2026
Merged

db: make floatToSql() a public static helper on DB#16
daveedis merged 2 commits into
mainfrom
float-to-sql-public

Conversation

@daveedis

@daveedis daveedis commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Makes floatToSql() callable from outside ZenDB so CMS Builder's backup dumper can format a PHP float as a SQL literal exactly the way ZenDB does.

Changes

  • floatToSql() moves from the ConnectionInternals trait to DBInternals, next to assertIdentifier(), as public static function floatToSql(float $value, string $context = 'value'): string, marked @internal the same way. Body and docblock are unchanged.
  • The three callers in ConnectionInternals (escape(), escapef(), the placeholder value converter) now call DB::floatToSql().
  • Import lists updated: is_finite and var_export added to DBInternals, is_finite dropped from ConnectionInternals where nothing else used it.
  • No behaviour change: same output, same InvalidArgumentException for NAN and INF.
  • Not added to the public docs or docs/ai-reference.md since it stays @internal.

Tests

New tests/ValueTypes/FloatToSqlTest.php covers:

input literal
0.1 0.1
1234567890.1234567 1234567890.1234567
0.3 - 0.1 0.19999999999999998
1.0E+20 1.0E+20
-2.5E-7 -2.5E-7
3.0 3.0
-0.0 -0.0

NAN, INF, and -INF throw InvalidArgumentException with the context word in the message.

Full suite: 1561 tests, 4285 assertions, 4 skipped (all environmental: no time_zone tables, SSL refused, mysqli::quote_string needs PHP 8.6, functional indexes need MySQL 8.0.13+). All existing escape, escapef, numeric, and placeholder float tests pass unchanged.

- moved from ConnectionInternals to DBInternals, next to assertIdentifier(),
  marked @internal the same way
- escape(), escapef(), and the placeholder converter now call DB::floatToSql()
- same output and same NAN/INF exception as before
- new FloatToSqlTest pins the literal spelling and the exceptions

Lets CMS Builder's backup dumper format floats exactly the way ZenDB does.
It formats a value for SQL, so it belongs with escape(), escapef(), and
escapeCSV() rather than under Validation.
@daveedis
daveedis merged commit 12c019c into main Sep 5, 2026
120 checks passed
@daveedis
daveedis deleted the float-to-sql-public branch September 5, 2026 18:38
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