Skip to content

Enable SQLite column metadata - #1204

Merged
crazywhalecc merged 1 commit into
crazywhalecc:mainfrom
JanJakes:fix/sqlite-column-metadata
Jul 7, 2026
Merged

crazywhalecc merged 1 commit into
crazywhalecc:mainfrom
JanJakes:fix/sqlite-column-metadata

Conversation

@JanJakes

@JanJakes JanJakes commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

What Changed

  • Enable SQLITE_ENABLE_COLUMN_METADATA for Unix SQLite builds so macOS/Linux match the existing Windows SQLite Makefile.
  • Remove the pdo_sqlite configure override that forced sqlite3_column_table_name=no.
  • Add sanity checks for both the SQLite compile option and PDO column table metadata.

Why

SQLITE_ENABLE_COLUMN_METADATA is optional in SQLite, but it is used in almost every libsqlite distribution on Linux, macOS, and Windows. When PHP bundled SQLite itself, it used the flag too, and PHP's own test suite covers that flag.

When the flag is missing, SQLite does not expose sqlite3_column_table_name() and PDO then cannot populate PDOStatement::getColumnMeta()['table'], which breaks consumers who rely on this metadata.

Evidence

  • Platform builds broadly enable column metadata. Roger Binns found COLUMN_METADATA enabled on macOS, Debian, Fedora, Gentoo, Arch, Termux, FreeBSD, OpenBSD, Homebrew, MacPorts, Nix, Haikuports, and msys2.
  • Additional builds follow the same pattern. I checked Ubuntu, Alpine, RHEL-family distros, Amazon Linux, openSUSE, and official PHP Docker images, including Alpine variants.
  • PHP expects this path to work. PHP's pdo_sqlite configure script probes sqlite3_column_table_name() and defines HAVE_SQLITE3_COLUMN_TABLE_NAME; PHP's own PDO SQLite test suite covers that flag.
  • Static PHP CLI already enables it on Windows. This PR makes macOS/Linux match the Windows behavior.

References

Build Unix SQLite with SQLITE_ENABLE_COLUMN_METADATA so the metadata APIs are available on macOS and Linux.

Remove the pdo_sqlite configure override that forced PHP to treat sqlite3_column_table_name() as unavailable, and add sanity checks for both SQLite compile options and PDO column metadata.

@crazywhalecc crazywhalecc left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

v3 branch should do this too.

@JanJakes

JanJakes commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

v3 branch should do this too.

@crazywhalecc Should I open another PR against v3, or would that be cherry-picked from main?

@crazywhalecc

crazywhalecc commented Jul 7, 2026 •

Copy link
Copy Markdown
Owner

v3 branch should do this too.

@crazywhalecc Should I open another PR against v3, or would that be cherry-picked from main?

Ah v3 is totally refactored version. You need to do similar changes on v3 branch and open another PR.

@JanJakes

JanJakes commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@crazywhalecc I gave it a shot in #1205.

@crazywhalecc
crazywhalecc merged commit 5329723 into crazywhalecc:main Jul 7, 2026
6 checks passed
@JanJakes
JanJakes deleted the fix/sqlite-column-metadata branch July 8, 2026 12:11
wojtekn added a commit to Automattic/studio that referenced this pull request Jul 9, 2026
## Related issues

- Related to STU-1968

## How AI was used in this PR

I used Claude Code to trace how Studio's native PHP is built and to bump
it to the latest trunk that includes the SQLITE_ENABLE_COLUMN_METADATA
fix.

## Proposed Changes

Studio's Native PHP runtime on macOS and Linux was built without SQLite
column metadata, so PDO could not report which table a result column
came from. This broke phpMyAdmin's unique-column detection, surfacing
the "Current selection does not contain a unique column" warning when
browsing tables (e.g. `wp_posts`) — even though the primary key was
correctly defined. The Sandbox/Playground runtime was unaffected because
its PHP is built with the metadata enabled, as is essentially every
mainstream PHP/SQLite distribution.

static-php-cli
[#1204](crazywhalecc/static-php-cli#1204) fixes
this upstream: it builds libsqlite3 with `SQLITE_ENABLE_COLUMN_METADATA`
and stops SPC from disabling `sqlite3_column_table_name()` in
`pdo_sqlite`'s configure. This PR pins the `Build PHP CLI Binaries`
workflow to that merged commit, which descends directly from the
previous pin (so the earlier centos 7 gd/libcurl link fix is retained).
Windows binaries come from php.net and already had metadata enabled, so
they are unchanged.

This is the workflow bump only. It has no effect until the build
workflow is run to produce new binaries and the resulting CDN metadata
PR lands (see Testing Instructions).

## Testing Instructions

This change ships nothing on its own — it changes which SPC ref future
builds use. To roll out the fix:

1. Merge this PR.
2. Run the **Build PHP CLI Binaries** workflow once per shipped PHP
minor (8.5.7, 8.4.22, 8.3.31, 8.2.31) with `package_version: studio-2`
(package IDs are immutable — a new value is required) and
`apps_cdn_visibility: external`.
3. Merge the metadata PR the workflow opens (updates
`packages/common/lib/php-binary-cdn-metadata.json` to the new `studio-2`
URLs + SHA-256).
4. Confirm packaged builds resolve the `studio-2` package for the
recommended version.

To verify the fix in a resulting build, on the Native runtime:
```php
$pdo = new PDO('sqlite::memory:');
$pdo->exec('CREATE TABLE wp_posts (ID INTEGER PRIMARY KEY, t TEXT)');
var_dump($pdo->query('SELECT ID FROM wp_posts')->getColumnMeta(0)['table']); // expect string "wp_posts"
```
Then browse a table in phpMyAdmin and confirm the "no unique column"
warning is gone. Verified locally on macOS arm64 (PHP 8.4.23 / SQLite
3.45.2): the `table` field is absent with the old ref and present with
#1204.

## Pre-merge Checklist

- [ ] Have you checked for TypeScript, React or other console errors?

---------

Co-authored-by: Riad Benguella <riad@Riads-MacBook-Air.local>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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