|
7 | 7 | use Closure; |
8 | 8 | use PHPUnit\Framework\TestCase; |
9 | 9 | use stdClass; |
| 10 | +use Yiisoft\Db\Command\Param; |
10 | 11 | use Yiisoft\Db\Exception\InvalidArgumentException; |
11 | 12 | use Yiisoft\Db\Exception\NotSupportedException; |
12 | 13 | use Yiisoft\Db\Expression\Expression; |
@@ -1930,4 +1931,56 @@ public function testUpsertExecute( |
1930 | 1931 | $command = $db->createCommand($actualSQL, $actualParams); |
1931 | 1932 | $command->execute(); |
1932 | 1933 | } |
| 1934 | + |
| 1935 | + public function testOverrideParameters1() |
| 1936 | + { |
| 1937 | + $db = $this->getConnection(); |
| 1938 | + |
| 1939 | + $params = [':id' => 1, ':pv2' => new Expression('(select type from {{%animal}}) where id=1')]; |
| 1940 | + $expression = new Expression('id = :id AND type = :pv2', $params); |
| 1941 | + |
| 1942 | + $query = new Query($db); |
| 1943 | + $query->select('*') |
| 1944 | + ->from('{{%animal}}') |
| 1945 | + ->andWhere($expression) |
| 1946 | + ->andWhere(['type' => new Param('test1', \PDO::PARAM_STR)]) |
| 1947 | + ; |
| 1948 | + |
| 1949 | + $command = $query->createCommand(); |
| 1950 | + $this->assertCount(3, $command->getParams()); |
| 1951 | + $this->assertEquals([':id', ':pv2', ':pv2_0',], array_keys($command->getParams())); |
| 1952 | + $this->assertEquals( |
| 1953 | + DbHelper::replaceQuotes( |
| 1954 | + 'SELECT * FROM [[animal]] WHERE (id = 1 AND type = (select type from {{%animal}}) where id=1) AND ([[type]]=\'test1\')', |
| 1955 | + $db->getName() |
| 1956 | + ), |
| 1957 | + $command->getRawSql() |
| 1958 | + ); |
| 1959 | + } |
| 1960 | + |
| 1961 | + public function testOverrideParameters2() |
| 1962 | + { |
| 1963 | + $db = $this->getConnection(); |
| 1964 | + |
| 1965 | + $expression = new Expression('id = :qp1', [':qp1' => 1]); |
| 1966 | + |
| 1967 | + $query = new Query($db); |
| 1968 | + $query->select('*') |
| 1969 | + ->from('{{%animal}}') |
| 1970 | + ->andWhere($expression) |
| 1971 | + ->andWhere(['type' => 'test2']) |
| 1972 | + ; |
| 1973 | + |
| 1974 | + $command = $query->createCommand(); |
| 1975 | + |
| 1976 | + $this->assertCount(2, $command->getParams()); |
| 1977 | + $this->assertEquals([':qp1', ':qp1_0',], array_keys($command->getParams())); |
| 1978 | + $this->assertEquals( |
| 1979 | + DbHelper::replaceQuotes( |
| 1980 | + 'SELECT * FROM [[animal]] WHERE (id = 1) AND ([[type]]=\'test2\')', |
| 1981 | + $db->getName() |
| 1982 | + ), |
| 1983 | + $command->getRawSql() |
| 1984 | + ); |
| 1985 | + } |
1933 | 1986 | } |
0 commit comments