Changeset 3084383
- Timestamp:
- 05/10/2024 07:30:52 AM (3 months ago)
- Location:
- sqlite-database-integration/trunk
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sqlite-database-integration/trunk/admin-page.php
r3007929 r3084383 59 59 <?php if ( defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) ) : ?> 60 60 <div class="notice notice-warning"> 61 <p> 61 <p> 62 <?php 63 printf( 64 /* translators: %s: db.php drop-in path */ 65 esc_html__( 'An older %s file was detected. Please click the button below to update the file.', 'sqlite-database-integration' ), 66 '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>' 67 ); 68 ?> 69 </p> 70 </div> 71 <a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?page=sqlite-integration&confirm-install&upgrade-from-pl' ), 'sqlite-install' ) ); ?>"> 62 72 <?php 63 73 printf( 64 74 /* translators: %s: db.php drop-in path */ 65 esc_html__( ' An older %s file was detected. Please click the button below to update the file.', 'sqlite-database-integration' ),75 esc_html__( '', 'sqlite-database-integration' ), 66 76 '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>' 67 77 ); 68 78 ?> 69 </p> 70 </div> 71 <a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?page=sqlite-integration&confirm-install&upgrade-from-pl' ), 'sqlite-install' ) ); ?>"> 72 <?php 73 printf( 74 /* translators: %s: db.php drop-in path */ 75 esc_html__( 'Update %s file', 'sqlite-database-integration' ), 76 '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>' 77 ); 78 ?> 79 </a> 79 </a> 80 80 <?php else : ?> 81 81 <div class="notice notice-error"> -
sqlite-database-integration/trunk/load.php
r3071334 r3084383 4 4 * Description: SQLite database driver drop-in. 5 5 * Author: The WordPress Team 6 * Version: 2.1. 96 * Version: 2.1. 7 7 * Requires PHP: 7.0 8 8 * Textdomain: sqlite-database-integration … … 15 15 define( 'SQLITE_MAIN_FILE', __FILE__ ); 16 16 17 17 18 require_once __DIR__ . '/admin-page.php'; 18 19 require_once __DIR__ . '/activate.php'; -
sqlite-database-integration/trunk/readme.txt
r3071334 r3084383 5 5 Tested up to: 6.4 6 6 Requires PHP: 5.6 7 Stable tag: 2.1. 97 Stable tag: 2.1. 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
sqlite-database-integration/trunk/wp-includes/sqlite/class-wp-sqlite-translator.php
r3071334 r3084383 1129 1129 * SQLite does not support this behavior, so we need to add the `ON CONFLICT REPLACE` clause to the column definition. 1130 1130 */ 1131 if ( $field->not_null) {1131 if () { 1132 1132 $definition .= ' ON CONFLICT REPLACE'; 1133 1133 } … … 1135 1135 * The value of DEFAULT can be NULL. PHP would print this as an empty string, so we need a special case for it. 1136 1136 */ 1137 if ( null === $field->default) {1137 if () { 1138 1138 $definition .= ' DEFAULT NULL'; 1139 } else if (false !== $field->default) {1139 } else) { 1140 1140 $definition .= ' DEFAULT ' . $field->default; 1141 } else if ($field->not_null) {1141 } else) { 1142 1142 /** 1143 1143 * If the column is NOT NULL, we need to provide a default value to match WPDB behavior caused by removing the STRICT_TRANS_TABLES mode. 1144 1144 */ 1145 if ( 'text' === $field->sqlite_data_type) {1145 if () { 1146 1146 $definition .= ' DEFAULT \'\''; 1147 } else if (in_array($field->sqlite_data_type, array('integer', 'real'), true)) {1147 } else) { 1148 1148 $definition .= ' DEFAULT 0'; 1149 1149 } … … 1439 1439 } 1440 1440 1441 1442 1443 1444 1441 1445 $this->rewriter->consume(); 1442 1446 } … … 1450 1454 $params = array(); 1451 1455 } elseif ( 1452 strpos( $updated_query, '@@SESSION.sql_mode' ) !== false 1453 || strpos( $updated_query, 'CONVERT( ' ) !== false 1456 // Examples: @@SESSION.sql_mode, @@GLOBAL.max_allowed_packet, @@character_set_client 1457 preg_match( '/@@((SESSION|GLOBAL)\s*\.\s*)?\w+\b/i', $updated_query ) === 1 || 1458 strpos( $updated_query, 'CONVERT( ' ) !== false 1454 1459 ) { 1455 1460 /* … … 1492 1497 1493 1498 /** 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1494 1564 * Executes a TRUNCATE statement. 1495 1565 */ … … 1516 1586 $this->rewriter->skip(); 1517 1587 $this->table_name = $this->rewriter->consume()->value; 1518 $stmt = $this->execute_sqlite_query( 1588 $this->set_results_from_fetched_data( 1589 $this->describe( $this->table_name ) 1590 ); 1591 if ( ! $this->results ) { 1592 throw new PDOException( 'Table not found' ); 1593 } 1594 } 1595 1596 /** 1597 * Executes a SELECT statement. 1598 * 1599 * @param string $table_name The table name. 1600 * 1601 * @return array 1602 */ 1603 private function describe( $table_name ) { 1604 return $this->execute_sqlite_query( 1519 1605 "SELECT 1520 1606 `name` as `Field`, … … 1525 1611 END 1526 1612 ) as `Null`, 1527 IFNULL(1613 ( 1528 1614 d.`mysql_type`, 1529 1615 ( … … 1545 1631 END 1546 1632 ) as `Key` 1547 FROM pragma_table_info(\"$t his->table_name\") p1633 FROM pragma_table_info(\"$table_name\") p 1548 1634 LEFT JOIN " . self::DATA_TYPES_CACHE_TABLE . " d 1549 ON d.`table` = \"$t his->table_name\"1635 ON d.`table` = \"$table_name\" 1550 1636 AND d.`column_or_index` = p.`name` 1551 1637 ; 1552 1638 " 1553 ); 1554 $this->set_results_from_fetched_data( 1555 $stmt->fetchAll( $this->pdo_fetch_mode ) 1556 ); 1557 if ( ! $this->results ) { 1558 throw new PDOException( 'Table not found' ); 1559 } 1639 ) 1640 ->fetchAll( $this->pdo_fetch_mode ); 1560 1641 } 1561 1642 1562 1643 /** 1563 1644 * Executes an UPDATE statement. 1645 1646 1647 1648 1649 1650 1651 1652 1653 1564 1654 */ 1565 1655 private function execute_update() { 1566 $this->rewriter->consume(); // Update. 1567 1568 $params = array(); 1656 $this->rewriter->consume(); // Consume the UPDATE keyword. 1657 $has_where = false; 1658 $needs_closing_parenthesis = false; 1659 $params = array(); 1569 1660 while ( true ) { 1570 1661 $token = $this->rewriter->peek(); 1571 1662 if ( ! $token ) { 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1572 1694 break; 1573 1695 } … … 1595 1717 $this->rewriter->consume(); 1596 1718 } 1719 1720 1721 1722 1723 1724 1597 1725 $this->rewriter->consume_all(); 1598 1726 … … 1600 1728 $this->execute_sqlite_query( $updated_query, $params ); 1601 1729 $this->set_result_from_affected_rows(); 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1602 1763 } 1603 1764 … … 3100 3261 case 'COLUMNS FROM': 3101 3262 $table_name = $this->rewriter->consume()->token; 3102 $stmt = $this->execute_sqlite_query( 3103 "PRAGMA table_info(\"$table_name\");" 3104 ); 3105 /* @todo we may need to add the Extra column if anybdy needs it. 'auto_increment' is the value */ 3106 $name_map = array( 3107 'name' => 'Field', 3108 'type' => 'Type', 3109 'dflt_value' => 'Default', 3110 'cid' => null, 3111 'notnull' => null, 3112 'pk' => null, 3113 ); 3114 $columns = $stmt->fetchAll( $this->pdo_fetch_mode ); 3115 $columns = array_map( 3116 function ( $row ) use ( $name_map ) { 3117 $new = array(); 3118 $is_object = is_object( $row ); 3119 $row = $is_object ? (array) $row : $row; 3120 foreach ( $row as $k => $v ) { 3121 $k = array_key_exists( $k, $name_map ) ? $name_map [ $k ] : $k; 3122 if ( $k ) { 3123 $new[ $k ] = $v; 3124 } 3125 } 3126 if ( array_key_exists( 'notnull', $row ) ) { 3127 $new['Null'] = ( '1' === $row ['notnull'] ) ? 'NO' : 'YES'; 3128 } 3129 if ( array_key_exists( 'pk', $row ) ) { 3130 $new['Key'] = ( '1' === $row ['pk'] ) ? 'PRI' : ''; 3131 } 3132 return $is_object ? (object) $new : $new; 3133 }, 3134 $columns 3135 ); 3136 $this->set_results_from_fetched_data( $columns ); 3263 3264 $this->set_results_from_fetched_data( $this->get_columns_from( $table_name ) ); 3137 3265 return; 3138 3266 … … 3209 3337 return; 3210 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3211 3384 case 'TABLE STATUS': // FROM `database`. 3212 // Match the optional [{FROM | IN} db_name] 3385 // Match the optional [{FROM | IN} db_name] 3213 3386 $database_expression = $this->rewriter->consume(); 3214 if ( $database_expression->token === 'FROM' || $database_expression->token === 'IN') {3387 if ( ) { 3215 3388 $this->rewriter->consume(); 3216 3389 $database_expression = $this->rewriter->consume(); … … 3219 3392 $pattern = '%'; 3220 3393 // [LIKE 'pattern' | WHERE expr] 3221 if ($database_expression->token === 'LIKE') {3394 if) { 3222 3395 $pattern = $this->rewriter->consume()->value; 3223 } else if($database_expression->token === 'WHERE') {3396 } else) { 3224 3397 // @TODO Support me please. 3225 } else if($database_expression->token !== ';') {3226 throw new Exception( 'Syntax error: Unexpected token ' . $database_expression->token . ' in query '. $this->mysql_query );3398 } else) { 3399 throw new Exception( 'Syntax error: Unexpected token ' . $database_expression->token .. $this->mysql_query ); 3227 3400 } 3228 3401 … … 3253 3426 AND name LIKE :pattern 3254 3427 ORDER BY name", 3255 3256 3428 array( 3257 3429 ':pattern' => $pattern, 3258 3430 ) 3259 3431 ); 3260 $tables = $this->strip_sqlite_system_tables( $stmt->fetchAll( $this->pdo_fetch_mode ) );3432 $tables = $this->strip_sqlite_system_tables( $stmt->fetchAll( $this->pdo_fetch_mode ) ); 3261 3433 foreach ( $tables as $table ) { 3262 3434 $table_name = $table->Name; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase … … 3305 3477 } 3306 3478 } 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3307 3524 } 3308 3525 -
sqlite-database-integration/trunk/wp-includes/sqlite/install-functions.php
r3015055 r3084383 32 32 } 33 33 34 $translator = new WP_SQLite_Translator( $pdo , $GLOBALS['table_prefix']);34 $translator = new WP_SQLite_Translator( $pdo ); 35 35 $query = null; 36 36
Note: See TracChangeset
for help on using the changeset viewer.