Skip to content
Snippets Groups Projects
Verified Commit 6eda609d authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3491222 by quietone: Fix Drupal.Commenting.FunctionComment.Missing in Database files

parent 6127aa9f
No related branches found
No related tags found
No related merge requests found
Showing
with 85 additions and 3 deletions
......@@ -1112,7 +1112,7 @@ public function transactionManager(): TransactionManagerInterface {
* @throws \LogicException
* If the transaction manager is undefined or unavailable.
*/
// phpcs:ignore Drupal.Commenting.FunctionComment.InvalidNoReturn
// phpcs:ignore Drupal.Commenting.FunctionComment.InvalidNoReturn, Drupal.Commenting.FunctionComment.Missing
protected function driverTransactionManager(): TransactionManagerInterface {
throw new \LogicException('The database driver has no TransactionManager implementation');
}
......
......@@ -547,7 +547,7 @@ abstract public function dropIndex($table, $name);
* @throws \RuntimeException
* If the driver does not implement this method.
*/
// phpcs:ignore Drupal.Commenting.FunctionComment.InvalidNoReturn
// phpcs:ignore Drupal.Commenting.FunctionComment.InvalidNoReturn, Drupal.Commenting.FunctionComment.Missing
protected function introspectIndexSchema($table) {
if (!$this->tableExists($table)) {
throw new SchemaObjectDoesNotExistException("The table $table doesn't exist.");
......@@ -668,7 +668,7 @@ public function createTable($name, $table) {
* make it private for each driver, and ::createTable actually an abstract
* method here for implementation in each driver.
*/
// phpcs:ignore Drupal.Commenting.FunctionComment.InvalidNoReturn
// phpcs:ignore Drupal.Commenting.FunctionComment.InvalidNoReturn, Drupal.Commenting.FunctionComment.Missing
protected function createTableSql($name, $table) {
throw new \BadMethodCallException(get_class($this) . '::createTableSql() not implemented.');
}
......
......@@ -212,6 +212,9 @@ public static function open(array &$connection_options = []) {
return $pdo;
}
/**
* {@inheritdoc}
*/
public function queryRange($query, $from, $count, array $args = [], array $options = []) {
return $this->query($query . ' LIMIT ' . (int) $from . ', ' . (int) $count, $args, $options);
}
......@@ -225,6 +228,9 @@ public function queryTemporary($query, array $args = [], array $options = []) {
return $tablename;
}
/**
* {@inheritdoc}
*/
public function driver() {
return 'mysql';
}
......@@ -279,6 +285,9 @@ protected function getServerVersion(): string {
return $this->serverVersion;
}
/**
* {@inheritdoc}
*/
public function databaseType() {
return 'mysql';
}
......@@ -305,6 +314,9 @@ public function createDatabase($database) {
}
}
/**
* {@inheritdoc}
*/
public function mapConditionOperator($operator) {
// We don't want to override any of the defaults.
return NULL;
......
......@@ -9,6 +9,9 @@
*/
class Insert extends QueryInsert {
/**
* {@inheritdoc}
*/
public function execute() {
if (!$this->preExecute()) {
return NULL;
......@@ -44,6 +47,9 @@ public function execute() {
return $last_insert_id;
}
/**
* {@inheritdoc}
*/
public function __toString() {
// Create a sanitized comment string to prepend to the query.
$comments = $this->connection->makeComment($this->comments);
......
......@@ -271,6 +271,9 @@ public function getFieldTypeMap() {
return $map;
}
/**
* Creates the keys for an SQL table.
*/
protected function createKeysSql($spec) {
$keys = [];
......@@ -355,6 +358,9 @@ protected function shortenIndex(&$index) {
}
}
/**
* Creates an SQL key for the given fields.
*/
protected function createKeySql($fields) {
$return = [];
foreach ($fields as $field) {
......
......@@ -255,6 +255,9 @@ public function prepareStatement(string $query, array $options, bool $allow_row_
return parent::prepareStatement($query, $options, $allow_row_count);
}
/**
* {@inheritdoc}
*/
public function queryRange($query, $from, $count, array $args = [], array $options = []) {
return $this->query($query . ' LIMIT ' . (int) $count . ' OFFSET ' . (int) $from, $args, $options);
}
......@@ -268,10 +271,16 @@ public function queryTemporary($query, array $args = [], array $options = []) {
return $tablename;
}
/**
* {@inheritdoc}
*/
public function driver() {
return 'pgsql';
}
/**
* {@inheritdoc}
*/
public function databaseType() {
return 'pgsql';
}
......@@ -318,6 +327,9 @@ public function createDatabase($database) {
}
}
/**
* {@inheritdoc}
*/
public function mapConditionOperator($operator) {
return static::$postgresqlConditionOperatorMap[$operator] ?? NULL;
}
......
......@@ -17,6 +17,9 @@
*/
class Insert extends QueryInsert {
/**
* {@inheritdoc}
*/
public function execute() {
if (!$this->preExecute()) {
return NULL;
......@@ -102,6 +105,9 @@ public function execute() {
return $last_insert_id ?? NULL;
}
/**
* {@inheritdoc}
*/
public function __toString() {
// Create a sanitized comment string to prepend to the query.
$comments = $this->connection->makeComment($this->comments);
......
......@@ -471,6 +471,9 @@ public function getFieldTypeMap() {
return $map;
}
/**
* Creates the SQL key for the given fields.
*/
protected function _createKeySql($fields) {
$return = [];
foreach ($fields as $field) {
......@@ -1020,12 +1023,18 @@ public function changeField($table, $field, $field_new, $spec, $new_keys = []) {
$this->resetTableInformation($table);
}
/**
* Creates a statement for an SQL index for the given fields.
*/
protected function _createIndexSql($table, $name, $fields) {
$query = 'CREATE INDEX ' . $this->ensureIdentifiersLength($table, $name, 'idx') . ' ON {' . $table . '} (';
$query .= $this->_createKeySql($fields) . ')';
return $query;
}
/**
* Adds keys for an SQL table.
*/
protected function _createKeys($table, $new_keys) {
if (isset($new_keys['primary key'])) {
$this->addPrimaryKey($table, $new_keys['primary key']);
......
......@@ -14,6 +14,9 @@
*/
class Select extends QuerySelect {
/**
* {@inheritdoc}
*/
public function orderRandom() {
$alias = $this->addExpression('RANDOM()', 'random_field');
$this->orderBy($alias);
......
......@@ -10,6 +10,9 @@
*/
class Update extends QueryUpdate {
/**
* {@inheritdoc}
*/
public function execute() {
$max_placeholder = 0;
$blobs = [];
......
......@@ -347,6 +347,9 @@ public static function sqlFunctionLikeBinary($pattern, $subject) {
return preg_match('/^' . $pattern . '$/', $subject);
}
/**
* {@inheritdoc}
*/
public function queryRange($query, $from, $count, array $args = [], array $options = []) {
return $this->query($query . ' LIMIT ' . (int) $from . ', ' . (int) $count, $args, $options);
}
......@@ -367,10 +370,16 @@ public function queryTemporary($query, array $args = [], array $options = []) {
return 'temp.' . $tablename;
}
/**
* {@inheritdoc}
*/
public function driver() {
return 'sqlite';
}
/**
* {@inheritdoc}
*/
public function databaseType() {
return 'sqlite';
}
......@@ -391,6 +400,9 @@ public function createDatabase($database) {
}
}
/**
* {@inheritdoc}
*/
public function mapConditionOperator($operator) {
return static::$sqliteConditionOperatorMap[$operator] ?? NULL;
}
......
......@@ -9,6 +9,9 @@
*/
class Select extends QuerySelect {
/**
* {@inheritdoc}
*/
public function forUpdate($set = TRUE) {
// SQLite does not support FOR UPDATE so nothing to do.
return $this;
......
......@@ -12,6 +12,9 @@
*/
class Truncate extends QueryTruncate {
/**
* {@inheritdoc}
*/
public function __toString() {
// Create a sanitized comment string to prepend to the query.
$comments = $this->connection->makeComment($this->comments);
......
......@@ -78,6 +78,7 @@
<include-pattern>core/modules/*/Plugin/views/display/*</include-pattern>
<include-pattern>core/modules/*/Plugin/views/exposed_form/*</include-pattern>
<include-pattern>core/modules/*/Plugin/views/field/*</include-pattern>
<include-pattern>*/Database/*</include-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>
<rule ref="Drupal.Commenting.FunctionComment.MissingParamType">
......
......@@ -21,6 +21,9 @@ public function testSelectLeast($values, $expected): void {
$this->assertEquals($expected, $least);
}
/**
* Provides data for testing the LEAST operator.
*/
public static function selectLeastProvider() {
return [
[[1, 2, 3, 4, 5, 6], 1],
......
......@@ -175,6 +175,9 @@ public function testCompileWithSqlInjectionForOperator($operator): void {
$condition->compile($connection, $query_placeholder);
}
/**
* Provides data for testing SQL injection.
*/
public static function providerTestCompileWithSqlInjectionForOperator() {
$data = [];
$data[] = ["IS NOT NULL) ;INSERT INTO {test} (name) VALUES ('test12345678'); -- "];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment