PluginProbe
SQLite Database Integration / 3.0.1
SQLite Database Integration v3.0.1
3.0.2 3.0.1 trunk 2.1.13 2.1.14 2.1.15 2.1.16 2.2.0 2.2.1 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.17 2.2.18 2.2.19 2.2.2 2.2.20 2.2.21 2.2.22 2.2.23 2.2.3 All 32 releases
sqlite-database-integration / wp-includes / database / mysql / class-wp-mysql-parser.php

class-wp-mysql-parser.php in SQLite Database Integration 3.0.1, at wp-includes/database/mysql/class-wp-mysql-parser.php

69 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * MySQL parser used by the SQLite driver.
5 *
6 * @access private
7 */
8 class WP_MySQL_Parser extends WP_Parser {
9 /**
10 * The current query AST.
11 *
12 * @var WP_Parser_Node|null
13 */
14 private $current_ast;
15
16 /**
17 * Reset this parser with a new token stream.
18 *
19 * @param array<WP_Parser_Token> $tokens The parser tokens.
20 */
21 public function reset_tokens( array $tokens ): void {
22 $this->tokens = $tokens;
23 $this->position = 0;
24 $this->current_ast = null;
25 }
26
27 /**
28 * Parse the next query from the input SQL string.
29 *
30 * This method reads tokens until a query is parsed, or the parsing fails.
31 * It returns a boolean indicating whether a query was successfully parsed.
32 *
33 * Example:
34 *
35 * // Parse all queries in the input SQL string.
36 * $parser = new WP_MySQL_Parser( $sql );
37 * while ( $parser->next_query() ) {
38 * $ast = $parser->get_query_ast();
39 * if ( ! $ast ) {
40 * // The parsing failed.
41 * }
42 * // The query was successfully parsed.
43 * }
44 *
45 * @return bool Whether a query was successfully parsed.
46 */
47 public function next_query(): bool {
48 if ( $this->position >= count( $this->tokens ) ) {
49 return false;
50 }
51 $this->current_ast = $this->parse();
52 return true;
53 }
54
55 /**
56 * Get the current query AST.
57 *
58 * When no query has been parsed yet, the parsing failed, or the end of the
59 * input was reached, this method returns null.
60 *
61 * @see WP_MySQL_Parser::next_query() for usage example.
62 *
63 * @return WP_Parser_Node|null The current query AST, or null if no query was parsed.
64 */
65 public function get_query_ast(): ?WP_Parser_Node {
66 return $this->current_ast;
67 }
68 }
69