Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WP_SQLite_Driver::query() API #7

Open
JanJakes opened this issue Feb 5, 2025 · 0 comments
Open

WP_SQLite_Driver::query() API #7

JanJakes opened this issue Feb 5, 2025 · 0 comments

Comments

@JanJakes
Copy link
Contributor

JanJakes commented Feb 5, 2025

Historically, the API of WP_SQLite_Driver::query() is the following:

/**
 * @param string  $query               Full SQL statement string.
 * @param int     $fetch_mode          PDO fetch mode. Default is PDO::FETCH_OBJ.
 * @param array   ...$fetch_mode_args  Additional fetch mode arguments.
 * @return mixed                       Return value, depending on the query type.
 */
publuc function query( string $query, $fetch_mode = PDO::FETCH_OBJ, ...$fetch_mode_args );

The return value is a WPDB-like construct, where DDL queries return true, insert/update/delete queries return the number of affected rows, and read queries return the number of returned rows.

Getting results and other values is then done via $driver->get_query_results(), $driver->get_insert_id(), etc. This part resembles the PDOStatement API and Doctrine DBAL's Result. In a way, the driver is mixing multiple things together.


To have a universal WP-independent API, I'd like to modify it to something like this:

publuc function query( string $query, array $params = array() ): <Result>;

The <Result> would be something like PDOStatement or Doctrine DBAL's Result class with methods to fetch data from the query, get the affected row count, and more.

We can return actual PDO Statements from the driver, but since the query translation is not 1:1, we'd need to pass the statement some explicit values in some cases. That means subclassing the PDOStatement class and making some of the values configurable. An alternative is to have a custom Result type, or exposing the fetch and similar methods on the driver itself.

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

No branches or pull requests

1 participant