|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * The SQLite driver uses PDO. Enable PDO function calls: |
| 5 | + * phpcs:disable WordPress.DB.RestrictedClasses.mysql__PDO |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * Deprecated: A proxy of the WP_MySQL_On_SQLite class preserving legacy API. |
| 10 | + * |
| 11 | + * This is a temporary class to preserve the legacy API for easier transition |
| 12 | + * to the new PDO-based API, developed in the "WP_MySQL_On_SQLite" class. |
| 13 | + */ |
| 14 | +class WP_SQLite_Driver { |
| 15 | + /** @var string */ |
| 16 | + public $client_info; |
| 17 | + |
| 18 | + /** @var WP_MySQL_On_SQLite */ |
| 19 | + private $mysql_on_sqlite_driver; |
| 20 | + |
| 21 | + public function __construct( |
| 22 | + WP_SQLite_Connection $connection, |
| 23 | + string $database, |
| 24 | + int $mysql_version = 80038 |
| 25 | + ) { |
| 26 | + $this->mysql_on_sqlite_driver = new WP_MySQL_On_SQLite( $connection, $database, $mysql_version ); |
| 27 | + $this->main_db_name = $database; |
| 28 | + $this->client_info = $this->mysql_on_sqlite_driver->client_info; |
| 29 | + } |
| 30 | + |
| 31 | + public function get_connection(): WP_SQLite_Connection { |
| 32 | + return $this->mysql_on_sqlite_driver->get_connection(); |
| 33 | + } |
| 34 | + |
| 35 | + public function get_sqlite_version(): string { |
| 36 | + return $this->mysql_on_sqlite_driver->get_sqlite_version(); |
| 37 | + } |
| 38 | + |
| 39 | + public function get_saved_driver_version(): string { |
| 40 | + return $this->mysql_on_sqlite_driver->get_saved_driver_version(); |
| 41 | + } |
| 42 | + |
| 43 | + public function is_sql_mode_active( string $mode ): bool { |
| 44 | + return $this->mysql_on_sqlite_driver->is_sql_mode_active( $mode ); |
| 45 | + } |
| 46 | + |
| 47 | + public function get_last_mysql_query(): ?string { |
| 48 | + return $this->mysql_on_sqlite_driver->get_last_mysql_query(); |
| 49 | + } |
| 50 | + |
| 51 | + public function get_last_sqlite_queries(): array { |
| 52 | + return $this->mysql_on_sqlite_driver->get_last_sqlite_queries(); |
| 53 | + } |
| 54 | + |
| 55 | + /** @return int|string */ |
| 56 | + public function get_insert_id() { |
| 57 | + return $this->mysql_on_sqlite_driver->get_insert_id(); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * @param string $query Full SQL statement string. |
| 62 | + * @param int $fetch_mode PDO fetch mode. Default is PDO::FETCH_OBJ. |
| 63 | + * @param array ...$fetch_mode_args Additional fetch mode arguments. |
| 64 | + * |
| 65 | + * @return mixed Return value, depending on the query type. |
| 66 | + * |
| 67 | + * @throws WP_SQLite_Driver_Exception When the query execution fails. |
| 68 | + */ |
| 69 | + public function query( string $query, $fetch_mode = PDO::FETCH_OBJ, ...$fetch_mode_args ) { |
| 70 | + return $this->mysql_on_sqlite_driver->query( $query, $fetch_mode, ...$fetch_mode_args ); |
| 71 | + } |
| 72 | + |
| 73 | + public function create_parser( string $query ): WP_MySQL_Parser { |
| 74 | + return $this->mysql_on_sqlite_driver->create_parser( $query ); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * @return mixed |
| 79 | + */ |
| 80 | + public function get_query_results() { |
| 81 | + return $this->mysql_on_sqlite_driver->get_query_results(); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * @return mixed |
| 86 | + */ |
| 87 | + public function get_last_return_value() { |
| 88 | + return $this->mysql_on_sqlite_driver->get_last_return_value(); |
| 89 | + } |
| 90 | + |
| 91 | + public function get_last_column_count(): int { |
| 92 | + return $this->mysql_on_sqlite_driver->get_last_column_count(); |
| 93 | + } |
| 94 | + |
| 95 | + public function get_last_column_meta(): array { |
| 96 | + return $this->mysql_on_sqlite_driver->get_last_column_meta(); |
| 97 | + } |
| 98 | + |
| 99 | + public function execute_sqlite_query( string $sql, array $params = array() ): PDOStatement { |
| 100 | + return $this->mysql_on_sqlite_driver->execute_sqlite_query( $sql, $params ); |
| 101 | + } |
| 102 | + |
| 103 | + public function begin_transaction(): void { |
| 104 | + $this->mysql_on_sqlite_driver->begin_transaction(); |
| 105 | + } |
| 106 | + |
| 107 | + public function commit(): void { |
| 108 | + $this->mysql_on_sqlite_driver->commit(); |
| 109 | + } |
| 110 | + |
| 111 | + public function rollback(): void { |
| 112 | + $this->mysql_on_sqlite_driver->rollback(); |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Proxy also this private method, as it is used in tests. |
| 117 | + */ |
| 118 | + private function quote_mysql_utf8_string_literal( string $utf8_literal ): string { |
| 119 | + $closure = function ( string $utf8_literal ) { |
| 120 | + return $this->quote_mysql_utf8_string_literal( $utf8_literal ); |
| 121 | + }; |
| 122 | + return $closure->call( $this->mysql_on_sqlite_driver, $utf8_literal ); |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Proxy also the private property "$main_db_name", as it is used in tests. |
| 127 | + */ |
| 128 | + public function __set( string $name, $value ): void { |
| 129 | + if ( 'main_db_name' === $name ) { |
| 130 | + $closure = function ( string $value ) { |
| 131 | + $this->main_db_name = $value; |
| 132 | + }; |
| 133 | + $closure->call( $this->mysql_on_sqlite_driver, $value ); |
| 134 | + } |
| 135 | + } |
| 136 | +} |
0 commit comments