@@ -1596,109 +1596,15 @@ jobs:
15961596 assert old_a in src, 'SHOW TABLE STATUS auto_increment block not found'
15971597 src = src.replace(old_a, new_a, 1)
15981598
1599- # 17b. translate_table_ref information_schema.tables path.
1600- # Initialize $auto_increment_join before the per-column loop so
1601- # the return-time sprintf can append it to the FROM clause.
1602- old_b1 = (
1603- "\t\t\t$expanded_list = array();\n"
1604- "\t\t\tforeach ( $columns as $column ) {\n"
1605- )
1606- new_b1 = (
1607- "\t\t\t$expanded_list = array();\n"
1608- "\t\t\t$auto_increment_join = '';\n"
1609- "\t\t\tforeach ( $columns as $column ) {\n"
1610- )
1611- assert old_b1 in src, 'translate_table_ref expanded_list init not found'
1612- src = src.replace(old_b1, new_b1, 1)
1613-
1614- # Replace the elseif body that builds the auto_increment subquery.
1615- old_b2 = (
1616- "\t\t\t\t} elseif ( 'tables' === $table_name && 'AUTO_INCREMENT' === $column ) {\n"
1617- "\t\t\t\t\t// Inject the auto-increment values.\n"
1618- "\t\t\t\t\t$columns_table = $this->information_schema_builder->get_table_name( false, 'columns' );\n"
1619- "\t\t\t\t\t$has_sequence_table = (bool) $this->execute_sqlite_query(\n"
1620- "\t\t\t\t\t\t\"SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'sqlite_sequence'\"\n"
1621- "\t\t\t\t\t)->fetchColumn();\n"
1622- "\n"
1623- "\t\t\t\t\t$auto_increment_subquery = sprintf(\n"
1624- "\t\t\t\t\t\t\"(\n"
1625- "\t\t\t\t\t\t\tSELECT COALESCE(s.seq + 1, 1)\n"
1626- "\t\t\t\t\t\t\tFROM %s AS c\n"
1627- "\t\t\t\t\t\t\t%s\n"
1628- "\t\t\t\t\t\t\tWHERE c.extra = 'auto_increment'\n"
1629- "\t\t\t\t\t\t\tAND c.table_schema = %s.table_schema\n"
1630- "\t\t\t\t\t\t\tAND c.table_name = %s.table_name\n"
1631- "\t\t\t\t\t\t)\",\n"
1632- "\t\t\t\t\t\t$this->quote_sqlite_identifier( $columns_table ),\n"
1633- "\t\t\t\t\t\t$has_sequence_table\n"
1634- "\t\t\t\t\t\t\t? 'LEFT JOIN main.sqlite_sequence AS s ON s.name = c.table_name'\n"
1635- "\t\t\t\t\t\t\t: 'LEFT JOIN (SELECT 0 AS seq) AS s',\n"
1636- "\t\t\t\t\t\t$this->quote_sqlite_identifier( $table_name ),\n"
1637- "\t\t\t\t\t\t$this->quote_sqlite_identifier( $table_name )\n"
1638- "\t\t\t\t\t);\n"
1639- "\n"
1640- "\t\t\t\t\t$expanded_list[] = sprintf( '%s AS %s', $auto_increment_subquery, $quoted_column );\n"
1641- )
1642- new_b2 = (
1643- "\t\t\t\t} elseif ( 'tables' === $table_name && 'AUTO_INCREMENT' === $column ) {\n"
1644- "\t\t\t\t\t// JOIN-based AUTO_INCREMENT (Turso mis-evaluates correlated form).\n"
1645- "\t\t\t\t\t$columns_table = $this->information_schema_builder->get_table_name( false, 'columns' );\n"
1646- "\t\t\t\t\t$has_sequence_table = (bool) $this->execute_sqlite_query(\n"
1647- "\t\t\t\t\t\t\"SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'sqlite_sequence'\"\n"
1648- "\t\t\t\t\t)->fetchColumn();\n"
1649- "\n"
1650- "\t\t\t\t\t$tables_alias = $this->quote_sqlite_identifier( $table_name );\n"
1651- "\t\t\t\t\t$auto_increment_join = sprintf(\n"
1652- "\t\t\t\t\t\t\" LEFT JOIN (\n"
1653- "\t\t\t\t\t\t\tSELECT table_schema AS ai_schema, table_name AS ai_name, 1 AS has_ai\n"
1654- "\t\t\t\t\t\t\tFROM %s\n"
1655- "\t\t\t\t\t\t\tWHERE extra = 'auto_increment'\n"
1656- "\t\t\t\t\t\t\tGROUP BY table_schema, table_name\n"
1657- "\t\t\t\t\t\t) AS ai ON ai.ai_schema = %s.table_schema AND ai.ai_name = %s.table_name\",\n"
1658- "\t\t\t\t\t\t$this->quote_sqlite_identifier( $columns_table ),\n"
1659- "\t\t\t\t\t\t$tables_alias,\n"
1660- "\t\t\t\t\t\t$tables_alias\n"
1661- "\t\t\t\t\t);\n"
1662- "\t\t\t\t\tif ( $has_sequence_table ) {\n"
1663- "\t\t\t\t\t\t$auto_increment_join .= sprintf(\n"
1664- "\t\t\t\t\t\t\t' LEFT JOIN main.sqlite_sequence AS s ON s.name = %s.table_name',\n"
1665- "\t\t\t\t\t\t\t$tables_alias\n"
1666- "\t\t\t\t\t\t);\n"
1667- "\t\t\t\t\t\t$auto_increment_expr = 'CASE WHEN ai.has_ai = 1 THEN COALESCE(s.seq + 1, 1) ELSE NULL END';\n"
1668- "\t\t\t\t\t} else {\n"
1669- "\t\t\t\t\t\t$auto_increment_expr = 'CASE WHEN ai.has_ai = 1 THEN 1 ELSE NULL END';\n"
1670- "\t\t\t\t\t}\n"
1671- "\n"
1672- "\t\t\t\t\t$expanded_list[] = sprintf( '%s AS %s', $auto_increment_expr, $quoted_column );\n"
1673- )
1674- assert old_b2 in src, 'translate_table_ref AUTO_INCREMENT elseif not found'
1675- src = src.replace(old_b2, new_b2, 1)
1676-
1677- # Append the JOIN clause to the outer FROM in the return sprintf.
1678- old_b3 = (
1679- "\t\t\t// Compose information schema subquery.\n"
1680- "\t\t\treturn sprintf(\n"
1681- "\t\t\t\t'(SELECT %s FROM %s AS %s)',\n"
1682- "\t\t\t\t$column_list,\n"
1683- "\t\t\t\t$this->quote_sqlite_identifier( $sqlite_table_name ),\n"
1684- "\t\t\t\t$this->quote_sqlite_identifier( $table_name )\n"
1685- "\t\t\t);\n"
1686- )
1687- new_b3 = (
1688- "\t\t\t// Compose information schema subquery.\n"
1689- "\t\t\treturn sprintf(\n"
1690- "\t\t\t\t'(SELECT %s FROM %s AS %s%s)',\n"
1691- "\t\t\t\t$column_list,\n"
1692- "\t\t\t\t$this->quote_sqlite_identifier( $sqlite_table_name ),\n"
1693- "\t\t\t\t$this->quote_sqlite_identifier( $table_name ),\n"
1694- "\t\t\t\t$auto_increment_join\n"
1695- "\t\t\t);\n"
1696- )
1697- assert old_b3 in src, 'translate_table_ref return sprintf not found'
1698- src = src.replace(old_b3, new_b3, 1)
1699-
1599+ # NOTE: The matching translate_table_ref information_schema.tables
1600+ # path also has the buggy correlated subquery, but rewriting it to
1601+ # the JOIN form triggers a Turso SIGSEGV in testReconstructTable
1602+ # (the path is hypersensitive to information_schema.tables shape
1603+ # changes). Keep the correlated form there and accept the loss of
1604+ # testInformationSchemaTablesFilterByAutoIncrement until the Turso
1605+ # pager fragility is fixed upstream.
17001606 open(path, 'w').write(src)
1701- print('patched AUTO_INCREMENT correlated-subquery -> JOIN form (SHOW TABLE STATUS + information_schema.tables )')
1607+ print('patched AUTO_INCREMENT correlated-subquery -> JOIN form (SHOW TABLE STATUS only )')
17021608 PY
17031609
17041610 - name : Run PHPUnit tests against Turso DB
0 commit comments