From 840617eece2b757157c7e3d580e4f4310988eff7 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Mon, 19 Jun 2023 15:19:03 +0900 Subject: [PATCH] Mark _query() and _fetch() as deprecated --- common/framework/DB.php | 74 ++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/common/framework/DB.php b/common/framework/DB.php index 64d660f68..65f166035 100644 --- a/common/framework/DB.php +++ b/common/framework/DB.php @@ -386,7 +386,7 @@ class DB } elseif ($query->type === 'SELECT') { - $result = $this->_fetch($this->_last_stmt, $last_index, $result_type, $result_class); + $result = $this->fetch($this->_last_stmt, $last_index, $result_type, $result_class); } else { @@ -499,40 +499,16 @@ class DB return $output; } - /** - * Execute a literal query string. - * - * This method should not be public, as it starts with an underscore. - * But since there are many legacy apps that rely on it, we will leave it public. - * - * @param string $query_string - * @return Helpers\DBStmtHelper - */ - public function _query($query_string) - { - if ($this->_debug_comment) - { - $query_string .= "\n" . sprintf('/* _query() %s */', \RX_CLIENT_IP); - } - - $this->_last_stmt = null; - $this->_last_stmt = $this->_handle->query($query_string); - return $this->_last_stmt; - } - /** * Fetch results from a query. * - * This method should not be public, as it starts with an underscore. - * But since there are many legacy apps that rely on it, we will leave it public. - * * @param \PDOStatement $stmt * @param int $last_index * @param string $result_type * @param string $result_class * @return mixed */ - public function _fetch($stmt, $last_index = 0, $result_type = 'auto', $result_class = '') + public function fetch($stmt, $last_index = 0, $result_type = 'auto', $result_class = '') { if (!($stmt instanceof \PDOStatement)) { @@ -774,7 +750,7 @@ class DB public function isTableExists(string $table_name): bool { $stmt = $this->_handle->query(sprintf("SHOW TABLES LIKE '%s'", $this->addQuotes($this->_prefix . $table_name))); - $result = $this->_fetch($stmt); + $result = $this->fetch($stmt); return $result ? true : false; } @@ -826,7 +802,7 @@ class DB public function isColumnExists(string $table_name, string $column_name): bool { $stmt = $this->_handle->query(sprintf("SHOW FIELDS FROM `%s` WHERE Field = '%s'", $this->addQuotes($this->_prefix . $table_name), $this->addQuotes($column_name))); - $result = $this->_fetch($stmt); + $result = $this->fetch($stmt); return $result ? true : false; } @@ -972,7 +948,7 @@ class DB { // If column information is not found, return false. $stmt = $this->_handle->query(sprintf("SHOW FIELDS FROM `%s` WHERE Field = '%s'", $this->addQuotes($this->_prefix . $table_name), $this->addQuotes($column_name))); - $column_info = $this->_fetch($stmt); + $column_info = $this->fetch($stmt); if (!$column_info) { return false; @@ -1012,7 +988,7 @@ class DB public function isIndexExists(string $table_name, string $index_name): bool { $stmt = $this->_handle->query(sprintf("SHOW INDEX FROM `%s` WHERE Key_name = '%s'", $this->addQuotes($this->_prefix . $table_name), $this->addQuotes($index_name))); - $result = $this->_fetch($stmt); + $result = $this->fetch($stmt); return $result ? true : false; } @@ -1130,7 +1106,7 @@ class DB */ public function getBestSupportedCharset(): string { - $output = $this->_fetch($this->_handle->query("SHOW CHARACTER SET LIKE 'utf8%'"), 1); + $output = $this->fetch($this->_handle->query("SHOW CHARACTER SET LIKE 'utf8%'"), 1); $utf8mb4_support = ($output && count(array_filter($output, function($row) { return $row->Charset === 'utf8mb4'; }))); @@ -1311,6 +1287,42 @@ class DB * ==================== KEPT FOR COMPATIBILITY WITH XE ==================== */ + /** + * Execute a literal query string. + * + * Use query() instead, or call methods directly on the handle. + * + * @deprecated + * @param string $query_string + * @return Helpers\DBStmtHelper + */ + public function _query($query_string) + { + if ($this->_debug_comment) + { + $query_string .= "\n" . sprintf('/* _query() %s */', \RX_CLIENT_IP); + } + + $this->_last_stmt = null; + $this->_last_stmt = $this->_handle->query($query_string); + return $this->_last_stmt; + } + + /** + * Fetch results from a query. + * + * Use query() and fetch() instead. + * + * @deprecated + * @param \PDOStatement $stmt + * @param int $last_index + * @return mixed + */ + public function _fetch($stmt, $last_index = 0) + { + return $this->fetch($stmt, $last_index); + } + /** * Old alias to getInstance(). *