Skip to content

Commit a2e4758

Browse files
committed
Return all permissions
1 parent b13141c commit a2e4758

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

tests/WP_SQLite_Translator_Tests.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,42 @@ public function testSelectFromDual() {
146146
$this->assertEquals( 1, $result[0]->output );
147147
}
148148

149+
public function testLeftFunction1Char() {
150+
$result = $this->assertQuery(
151+
'SELECT LEFT("abc", 1) as output'
152+
);
153+
$this->assertEquals( "a", $result[0]->output );
154+
}
155+
156+
public function testLeftFunction5Chars() {
157+
$result = $this->assertQuery(
158+
'SELECT LEFT("Lorem ipsum", 5) as output'
159+
);
160+
$this->assertEquals( "Lorem", $result[0]->output );
161+
}
162+
163+
public function testLeftFunctionNullString() {
164+
$result = $this->assertQuery(
165+
'SELECT LEFT(NULL, 5) as output'
166+
);
167+
$this->assertEquals( null, $result[0]->output );
168+
}
169+
170+
public function testLeftFunctionNullLength() {
171+
$result = $this->assertQuery(
172+
'SELECT LEFT("Test", NULL) as output'
173+
);
174+
$this->assertEquals( null, $result[0]->output );
175+
}
176+
149177
public function testInsertSelectFromDual() {
150178
$result = $this->assertQuery(
151179
'INSERT INTO _options (option_name, option_value) SELECT "A", "b" FROM DUAL WHERE ( SELECT NULL FROM DUAL ) IS NULL'
152180
);
153181
$this->assertEquals( 1, $result );
154182
}
155183

184+
156185
public function testCreateTemporaryTable() {
157186
$this->assertQuery(
158187
"CREATE TEMPORARY TABLE _tmp_table (
@@ -1250,7 +1279,7 @@ public function testShowGrantsFor() {
12501279
$result,
12511280
array(
12521281
(object) array(
1253-
'Grants for root@localhost' => 'GRANT *.* ON % TO `root`@`localhost`'
1282+
'Grants for root@localhost' => 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION'
12541283
)
12551284
)
12561285
);

wp-includes/sqlite/class-wp-sqlite-translator.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,7 @@ private function translate_expression( $token ) {
18241824
|| $this->capture_group_by( $token )
18251825
|| $this->translate_ungrouped_having( $token )
18261826
|| $this->translate_like_escape( $token )
1827+
|| $this->translate_left_function( $token )
18271828
);
18281829
}
18291830

@@ -2025,6 +2026,41 @@ private function translate_date_add_sub( $token ) {
20252026
return true;
20262027
}
20272028

2029+
/**
2030+
* Translate the LEFT() function.
2031+
*
2032+
* > Returns the leftmost len characters from the string str, or NULL if any argument is NULL.
2033+
*
2034+
* https://dev.mysql.com/doc/refman/8.3/en/string-functions.html#function_left
2035+
*
2036+
* @param WP_SQLite_Token $token The token to translate.
2037+
*
2038+
* @return bool
2039+
*/
2040+
private function translate_left_function( $token ) {
2041+
if (
2042+
! $token->matches(
2043+
WP_SQLite_Token::TYPE_KEYWORD,
2044+
WP_SQLite_Token::FLAG_KEYWORD_FUNCTION,
2045+
array( 'LEFT' )
2046+
)
2047+
) {
2048+
return false;
2049+
}
2050+
2051+
$this->rewriter->skip();
2052+
$this->rewriter->add( new WP_SQLite_Token( 'SUBSTRING', WP_SQLite_Token::TYPE_KEYWORD, WP_SQLite_Token::FLAG_KEYWORD_FUNCTION ) );
2053+
$this->rewriter->consume(
2054+
array(
2055+
'type' => WP_SQLite_Token::TYPE_OPERATOR,
2056+
'value' => ',',
2057+
)
2058+
);
2059+
$this->rewriter->add( new WP_SQLite_Token( 1, WP_SQLite_Token::TYPE_NUMBER ) );
2060+
$this->rewriter->add( new WP_SQLite_Token( ',', WP_SQLite_Token::TYPE_OPERATOR ) );
2061+
return true;
2062+
}
2063+
20282064
/**
20292065
* Convert function aliases.
20302066
*
@@ -3029,7 +3065,7 @@ private function execute_show() {
30293065
case 'GRANTS FOR':
30303066
$this->set_results_from_fetched_data( array(
30313067
(object) array(
3032-
'Grants for root@localhost' => 'GRANT *.* ON % TO `root`@`localhost`',
3068+
'Grants for root@localhost' => 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION'
30333069
)
30343070
) );
30353071
return;

0 commit comments

Comments
 (0)