Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@
}
}

/**
* The DB_NAME constant is required by the SQLite driver.
*
* When DB_NAME is not defined, let's use a default value that corresponds to
* the default value of the constant in "wp-config-sample.php" and in Studio.
*/
if ( ! defined( 'DB_NAME' ) ) {
define( 'DB_NAME', 'database_name_here' );
Copy link
Copy Markdown
Collaborator

@adamziel adamziel Jul 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log a warning maybe? or would that not make sense?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamziel At the moment, this seems to be a valid use case in Studio that probably shouldn't even generate warnings, I guess.

That said, I think I figured out a way to make the information schema DB_NAME independent, so I think this will be only temporary. The idea is to use temporary views on top of the stored information schema tables. They are naturally per-session and enable injecting any DB_NAME to the affected columns, they are low cost to create (they don't materialize + it can be lazy), and they could also unlock features like row count and auto-increment values.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is not studio-specific, though, but distributed to all sites where the SQLite plugin is installed. Would that make a warning reasonable?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamziel the issue is not Studio-specific. It could happen on WoA sites, too, if user uses WordPress with SQLite plugin. WoA sites don't have database constants defined in wp-config.php file.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I guess it makes sense for any sqlite-only site to skip the database constants.

}

// Allow enabling the SQLite AST driver via environment variable.
if ( ! defined( 'WP_SQLITE_AST_DRIVER' ) && isset( $_ENV['WP_SQLITE_AST_DRIVER'] ) && 'true' === $_ENV['WP_SQLITE_AST_DRIVER'] ) {
define( 'WP_SQLITE_AST_DRIVER', true );
Expand Down