mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-09 01:45:36 +08:00
[v3] Enable SQLite column metadata (#1205)
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Package\Extension;
|
||||
|
||||
use Package\Target\php;
|
||||
use StaticPHP\Attribute\Package\BeforeStage;
|
||||
use StaticPHP\Attribute\Package\Extension;
|
||||
use StaticPHP\Package\PackageInstaller;
|
||||
use StaticPHP\Util\FileSystem;
|
||||
|
||||
#[Extension('pdo_sqlite')]
|
||||
class pdo_sqlite
|
||||
{
|
||||
#[BeforeStage('php', [php::class, 'configureForUnix'], 'ext-pdo_sqlite')]
|
||||
public function patchBeforeConfigure(PackageInstaller $installer): void
|
||||
{
|
||||
FileSystem::replaceFileRegex(
|
||||
"{$installer->getTargetPackage('php')->getSourceDir()}/configure",
|
||||
'/sqlite3_column_table_name=yes/',
|
||||
'sqlite3_column_table_name=no'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,12 @@ class sqlite
|
||||
#[BuildFor('Linux')]
|
||||
public function buildUnix(LibraryPackage $lib): void
|
||||
{
|
||||
UnixAutoconfExecutor::create($lib)->configure()->make();
|
||||
UnixAutoconfExecutor::create($lib)
|
||||
->appendEnv([
|
||||
'CFLAGS' => '-DSQLITE_ENABLE_COLUMN_METADATA=1',
|
||||
])
|
||||
->configure()
|
||||
->make();
|
||||
$lib->patchPkgconfPrefix(['sqlite3.pc']);
|
||||
}
|
||||
|
||||
|
||||
16
src/globals/ext-tests/pdo_sqlite.php
Normal file
16
src/globals/ext-tests/pdo_sqlite.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$pdo = new PDO('sqlite::memory:');
|
||||
$pdo->exec('CREATE TABLE spc_column_metadata_test (id INTEGER)');
|
||||
|
||||
$stmt = $pdo->query('SELECT id FROM spc_column_metadata_test');
|
||||
if ($stmt === false) {
|
||||
throw new RuntimeException('Failed to query SQLite metadata test table.');
|
||||
}
|
||||
|
||||
$metadata = $stmt->getColumnMeta(0);
|
||||
if (($metadata['table'] ?? null) !== 'spc_column_metadata_test') {
|
||||
throw new RuntimeException('PDO SQLite column metadata does not include the origin table.');
|
||||
}
|
||||
10
src/globals/ext-tests/sqlite3.php
Normal file
10
src/globals/ext-tests/sqlite3.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$sqlite = new SQLite3(':memory:');
|
||||
$enabled = $sqlite->querySingle("SELECT sqlite_compileoption_used('ENABLE_COLUMN_METADATA')");
|
||||
|
||||
if ((int) $enabled !== 1) {
|
||||
throw new RuntimeException('SQLite was not built with SQLITE_ENABLE_COLUMN_METADATA.');
|
||||
}
|
||||
Reference in New Issue
Block a user