Skip to content

Conversation

@JanJakes
Copy link
Member

@JanJakes JanJakes commented Jun 6, 2025

Require DB_NAME to be set only in the new driver.

As reported in #194 (comment):

I have this plugin on a site, and the Plugins admin page offered me the upgrade. I upgraded, and it broke the site, due to previously I did not have define( 'DB_NAME', '...' ); in wp-config.php.

The error message was:

Error: Undefined constant "DB_NAME" in .../wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/db.php on line 69

@JanJakes JanJakes requested a review from adamziel June 6, 2025 09:15
@adamziel
Copy link
Collaborator

adamziel commented Jun 6, 2025

In the new message let's explain it's about the DB_NAME constant and why do we need it in SQLite

@JanJakes
Copy link
Member Author

JanJakes commented Jun 6, 2025

@adamziel 👍 I improved the comment.

@adamziel adamziel merged commit e401ef1 into develop Jun 6, 2025
12 checks passed
@JanJakes JanJakes mentioned this pull request Oct 14, 2025
JanJakes added a commit that referenced this pull request Oct 15, 2025
This PR replaces
#262. It is
a simpler solution to the same problem:

When a table reference targets an information schema table, we replace
it with a subquery, injecting the configured database name dynamically:

```sql
-- The following query:
SELECT *, t.*, t.table_schema FROM information_schema.tables t

-- Will be translated to:
SELECT *, t.*, t.table_schema FROM (
  SELECT
    `TABLE_CATALOG`,
    IIF(`TABLE_SCHEMA` = 'information_schema', `TABLE_SCHEMA`, 'database_name') AS `TABLE_SCHEMA`,
    `TABLE_NAME`,
    ...
  FROM _wp_sqlite_mysql_information_schema_tables AS tables
) t
```
The same logic will be applied to table references in JOIN clauses as
well.

---

With the new SQLite driver, we keep running into issues with missing and
incorrect database name values
(#197,
#203,
#226,
#260,
#261, and
other issues).

Thinking through this further, I came to the conclusion that to provide
maximum flexibility and portability, it would be best to provide an API
in the shape of:

_"Mount `my-sqlite-file.sqlite` as `my-db-name`."_

Even if we consider adding multi-database support one day, it would
still be great to allow mounting additional SQLite files under dynamic
database names.

I don't see any downsides to doing this, except maybe that we'll have to
choose some database name in some scenarios, such as in database admin
tools. However, in these cases we can use a reasonable default or the
file name.

This is a WIP pull request demonstrating the simplest approach. For it
to be merged, I only need to resolve how the existing database name
values should be treated.
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.

3 participants