Skip to content

Bind a NaN or an infinity as a BINARY_DOUBLE on Oracle, where the driver refused it - #599

Merged
jasperblues merged 4 commits into
mainfrom
oracle-nonfinite-575
Nov 27, 2026
Merged

jasperblues merged 4 commits into
mainfrom
oracle-nonfinite-575

Conversation

@jasperblues

@jasperblues jasperblues commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Closes #575

On Oracle, a NaN or an infinity bound to a SQL statement was refused before it reached the store: DPY-4004: invalid number. python-oracledb binds a Python float as a NUMBER, and a NUMBER holds neither. A Decimal that is no finite number is bound as the float it stands for (#303), so it was refused too. For example, pm.query(QuerySpecification('SELECT $v FROM dual').bind({'v': float('inf')})) raised.

Now:

  • A float that is NaN or an infinity is bound as a BINARY_DOUBLE, which holds them. It is a cursor.var(oracledb.DB_TYPE_BINARY_DOUBLE) holding the value. It reads back as the float, compares as a number, and stores in a BINARY_DOUBLE column, through query and through a cursor.
  • A finite float is still bound as a NUMBER, as the object manager's JSON writes take it.
  • A compiled Cypher statement isn't affected: it binds its values as JSON text, with NaN and the infinities in the store layout's own form.

Why the statement is also tagged: binding the variable alone wasn't enough. I measured this on Oracle with the bare driver:

  • If one SQL text's first run binds a BINARY_DOUBLE, a later run binding a NUMBER for the same name makes the next BINARY_DOUBLE run fail with ORA-01426: numeric overflow. Oracle shares its cursor for the text and reads the value as a NUMBER.
  • A text whose first run bound a NUMBER doesn't fail. Texts that differ by their binds' kinds don't either.

So a statement that binds a NaN or an infinity gets a comment, on a line of its own, naming those binds: /* drivine: binary doubles b0 */. That keeps it on its own shared cursor. _BLOCK.match still reads the untagged text.

Tests:

  • Oracle, in tests/integration/oracle/test_oracle_connection.py (and the generated sync copy):
    • a float and a Decimal NaN or infinity read back as the float;
    • comparisons with them, and storage into a BINARY_DOUBLE column;
    • a finite float unchanged;
    • a cursor binding an infinity;
    • one statement given inf, 2.5, 7 and -inf through a query, then inf through a cursor. This sequence failed without the tag.
  • Unit, in tests/unit/test_oracle_statement_cache.py, with no database:
    • the binds' types;
    • the tag for one and several doubles, and none without them;
    • a statement ending in a -- comment.

Whole suite with Oracle (ORACLE_TESTS=true) on the final commit:

  • tests/integration: 4714 passed, 291 skipped, 7 xfailed, 1 xpassed, 0 failed
  • tests/sync_integration: 4644 passed, 290 skipped, 7 xfailed, 1 xpassed, 0 failed
  • Unit: 3228 passed.

drivine4j refuses them too: on Oracle, a Double NaN bound to plain SQL fails with NaN, and an infinity with Overflow, from Oracle's JDBC driver. A port follows. Drivine for TypeScript is being checked.

Review: 2 passes, last CLEAN.

  • Pass 1 added the unit tests of the binds and the tag, and corrected _bindable's docstring to say a finite float is still a NUMBER.
  • Pass 2 was CLEAN.

… which holds them, where the driver refused it as a NUMBER (#575)
…R-bound runs on Oracle, which then failed it with ORA-01426, and test a cursor and a mixed run (#575)
@jasperblues
jasperblues merged commit 53532ce into main Nov 27, 2026
16 checks passed
@jasperblues jasperblues mentioned this pull request Nov 29, 2026
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.

Oracle: a NaN or an infinity bound to a SQL statement is refused by the driver, as a NUMBER holds neither

1 participant