@@ -123,62 +123,68 @@ jobs:
123123 ignore-cache : " yes"
124124 composer-options : " --optimize-autoloader"
125125
126- - name : Staged reproduction of test setUp()
126+ - name : Diagnose createFunction behavior
127127 continue-on-error : true
128128 env :
129129 LD_PRELOAD : ${{ steps.turso-lib.outputs.path }}
130130 working-directory : packages/mysql-on-sqlite
131131 run : |
132- php -d 'output_buffering=0' <<'PHP'
132+ # Use STDERR for progress logging so it is always flushed immediately.
133+ php <<'PHP'
133134 <?php
134- require __DIR__ . '/tests/bootstrap.php';
135- echo "[1] bootstrap ok\n";
135+ $log = fn(string $s) => fwrite(STDERR, $s . "\n");
136136
137137 $pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
138138 $pdo = new $pdo_class('sqlite::memory:');
139- echo "[2] PDO({$pdo_class}) ok\n";
140-
141- $pdo->exec('PRAGMA foreign_keys = ON');
142- echo "[3] PRAGMA foreign_keys ok\n";
143-
144- // Same as WP_SQLite_PDO_User_Defined_Functions::register_for but with
145- // a running count so we see how far we got before any crash.
146- $funcs = new WP_SQLite_PDO_User_Defined_Functions();
147- $ref = new ReflectionClass($funcs);
148- $prop = $ref->getProperty('functions');
149- $prop->setAccessible(true);
150- $list = $prop->getValue($funcs);
151- echo "[4] UDF list: " . count($list) . " entries\n";
152-
153- $n = 0;
154- foreach ($list as $name => $method) {
155- $n++;
156- if ($pdo instanceof PDO\SQLite) {
157- $pdo->createFunction($name, [$funcs, $method]);
158- } else {
159- $pdo->sqliteCreateFunction($name, [$funcs, $method]);
160- }
161- echo "[5.{$n}] registered {$name}\n";
139+ $log("[a] PDO({$pdo_class}) ok");
140+
141+ // 1) Closure
142+ try {
143+ $pdo->createFunction('mk_closure', function ($x) { return $x . '!'; });
144+ $log('[b] createFunction(closure) ok');
145+ $r = $pdo->query("SELECT mk_closure('x') AS v")->fetch(PDO::FETCH_ASSOC);
146+ $log('[b.call] ' . json_encode($r));
147+ } catch (\Throwable $e) {
148+ $log('[b] EXC ' . $e->getMessage());
162149 }
163- echo "[6] all UDFs registered\n";
164150
165- // Register a tiny extra query to see if calling a registered UDF from SQL works.
166- $row = $pdo->query("SELECT md5('x') AS v")->fetch(PDO::FETCH_ASSOC);
167- echo "[7] md5('x') -> " . json_encode($row) . "\n";
151+ // 2) String callable
152+ try {
153+ $pdo->createFunction('mk_builtin', 'md5');
154+ $log('[c] createFunction("md5") ok');
155+ $r = $pdo->query("SELECT mk_builtin('abc') AS v")->fetch(PDO::FETCH_ASSOC);
156+ $log('[c.call] ' . json_encode($r));
157+ } catch (\Throwable $e) {
158+ $log('[c] EXC ' . $e->getMessage());
159+ }
168160
169- // Now build the full driver.
170- $conn = new WP_SQLite_Connection(['pdo' => $pdo]);
171- echo "[8] Connection ok\n";
161+ // 3) [object, method] callable
162+ try {
163+ $obj = new class {
164+ public function greet($x) { return "hi $x"; }
165+ };
166+ $pdo->createFunction('mk_method', [$obj, 'greet']);
167+ $log('[d] createFunction([obj,method]) ok');
168+ $r = $pdo->query("SELECT mk_method('bob') AS v")->fetch(PDO::FETCH_ASSOC);
169+ $log('[d.call] ' . json_encode($r));
170+ } catch (\Throwable $e) {
171+ $log('[d] EXC ' . $e->getMessage());
172+ }
172173
173- $engine = new WP_SQLite_Driver($conn, 'wp');
174- echo "[9] Driver ok\n";
174+ // 4) Register many to see if limit matters.
175+ try {
176+ for ($i = 0; $i < 40; $i++) {
177+ $pdo->createFunction("fn_{$i}", function () { return 1; });
178+ if ($i === 30 || $i === 31 || $i === 32 || $i === 33 || $i === 39) {
179+ $log("[e.{$i}] registered fn_{$i}");
180+ }
181+ }
182+ $log('[e] bulk registration ok');
183+ } catch (\Throwable $e) {
184+ $log('[e] EXC at N=' . ($i ?? '?') . ': ' . $e->getMessage());
185+ }
175186
176- $engine->query("CREATE TABLE _options (
177- ID INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
178- option_name TEXT NOT NULL default '',
179- option_value TEXT NOT NULL default ''
180- );");
181- echo "[10] CREATE TABLE _options ok\n";
187+ $log('[done] script finished cleanly');
182188 PHP
183189
184190 - name : Run PHPUnit tests against Turso DB
0 commit comments