diff --git a/Tests/DatabaseQueryTest.php b/Tests/DatabaseQueryTest.php index e29402af..0ec6a97f 100644 --- a/Tests/DatabaseQueryTest.php +++ b/Tests/DatabaseQueryTest.php @@ -962,6 +962,30 @@ public function testBind($key, $value, $dataType, $expected) ); } + /** + * @testdox The bind method records a bound parameter for the query + * + * @param array|string|integer $key The key that will be used in your SQL query to reference the value. Usually of + * the form ':key', but can also be an integer. + * @param mixed $value The value that will be bound. It can be an array, in this case it has to be + * same length of $key; The value is passed by reference to support output + * parameters such as those possible with stored procedures. + * @param array|string $dataType Constant corresponding to a SQL datatype. It can be an array, in this case it + * has to be same length of $key + * @param array $expected The expected structure of `$bounded` + */ + public function testBindValue() + { + $this->assertSame($this->query, $this->query->bindValue(':bindValue', 'JustValueNoReference', ParameterType::STRING), 'The query builder supports method chaining'); + + $this->assertEquals( + [ + ':bindValue' => (object) ['value' => 'JustValueNoReference', 'dataType' => 'string', 'length' => 0, 'driverOptions' => []], + ], + $this->query->bounded + ); + } + /** * @testdox The bind method does not record bound parameters when the keys and values are an unbalanced number of items */ diff --git a/src/DatabaseQuery.php b/src/DatabaseQuery.php index 6abc16f8..831bf8b4 100644 --- a/src/DatabaseQuery.php +++ b/src/DatabaseQuery.php @@ -1939,6 +1939,30 @@ public function bind($key, &$value, $dataType = ParameterType::STRING, $length = return $this; } + /** + * Method to add a variable to an internal array that will be bound to a prepared SQL statement before query execution. + * + * Proxy method to self::bind() without the need to provide a referenceable input for value + * + * @param array|string|integer $key The key that will be used in your SQL query to reference the value. Usually of + * the form ':key', but can also be an integer. + * @param mixed $value The value that will be bound. It can be an array, in this case it has to be + * same length of $key + * @param array|string $dataType Constant corresponding to a SQL datatype. It can be an array, in this case it + * has to be same length of $key + * @param integer $length The length of the variable. Usually required for OUTPUT parameters. + * @param array $driverOptions Optional driver options to be used. + * + * @return $this + * + * @since __DEPLOY_VERSION__ + * @throws \InvalidArgumentException + */ + public function bindValue($key, $value, $dataType = ParameterType::STRING, $length = 0, $driverOptions = []) + { + return $this->bind($key, $value, $dataType, $length, $driverOptions); + } + /** * Method to unbind a bound variable. *