Skip to content

Render the MySQL dialect at render time - #90

Draft
simon-mundy wants to merge 3 commits into
php-db:rfc/256-platform-value-quotingfrom
simon-mundy:rfc/256-render-time-dialect
Draft

simon-mundy wants to merge 3 commits into
php-db:rfc/256-platform-value-quotingfrom
simon-mundy:rfc/256-render-time-dialect

Conversation

@simon-mundy

Copy link
Copy Markdown
Member

Renders the MySQL dialect through the render-time dialect in php-db/phpdb#261, replacing the statement subclasses.

Depends on php-db/phpdb#258 and php-db/phpdb#259, and on #88 and #89 here. This branch is stacked on #89.

What changes

  • AdapterPlatform::getStatementFactory() becomes getDialect(), which returns one Sql\Dialect instance.
  • Sql\Dialect names what MySQL renders differently from standard SQL:
    • For a select with an offset and no limit, the limit clause is the fixed clause LIMIT 18446744073709551615. Any other select is rendered as standard SQL.
    • Column definitions go through Sql\Ddl\ColumnOptionRenderer, which adds the MySQL column options and places an added column with AFTER. It uses the existing ColumnOptionTrait unchanged.
  • Removed: Sql\Platform, Sql\Select, Sql\Ddl\CreateTable and Sql\Ddl\AlterTable.

Why

The MySQL limit rule now applies to any Select the platform renders, so a subselect built with new Select() no longer renders an OFFSET without a LIMIT. The core pull request has the example.

Checked

  • Unit suite passes (202 tests) against the core branch. Mago format and lint are clean. Mago analysis reports one finding, in AdapterPlatform::quoteValue(), which is also reported on Refuse to quote a value the driver cannot quote #89 as it stands.
  • The DDL and select tests now render the standard statements through the MySQL platform, and SelectRenderingTest covers the subselect case as a string and as a prepared statement.

Not done

  • composer.json still requires dev-rfc/256-statement-factory, so CI here installs a core without the dialect interfaces and will fail until the core branch is available to require. The tests above were run with the core branch linked in locally.
  • The integration tests need a database and were not run.

Follows the phpdb change that applies the dialect when a statement is rendered. The MySQL Select,
CreateTable and AlterTable subclasses and the statement factory are replaced by a Dialect that
names what MySQL renders differently from standard SQL.

LimitRenderer supplies the maximum limit for a select that has an offset and no limit. It now
applies to any Select the platform renders, so a subselect built with new Select() no longer
renders an OFFSET without a LIMIT. ColumnOptionRenderer adds the MySQL column options to each
column definition and places an added column with AFTER, using the existing ColumnOptionTrait.

The DDL and select tests render the standard statements through the MySQL platform.
…a limit

The dialect lists the limit clause only for a select that has an offset and no limit, and gives
it as a FixedClause, so every other select is rendered without building a render context.
LimitRenderer had nothing left to decide and is removed.

ColumnOptionRenderer returns the standard definition for a column with no options, and builds
the AFTER resolver once.
The dialect built the maximum-limit clause and the column option renderer in its constructor,
and the renderer built its AFTER resolver in its own, whether or not a statement that needs
them was ever rendered. Each is now created the first time it is asked for and reused after.
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