-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix "FROM" with the specified database #80
base: 1.5
Are you sure you want to change the base?
Changes from all commits
3b6a58c
132ed95
38596ac
45ce309
fb037c1
6b05ac3
0abbba9
c8fc8dc
5c08718
2355589
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
namespace Mouf\Database\QueryWriter; | ||
|
||
use Doctrine\DBAL\Types\Type; | ||
use SQLParser\SqlRenderInterface; | ||
use function method_exists; | ||
use Mouf\Database\QueryWriter\Utils\DbHelper; | ||
use Mouf\Utils\Value\ValueUtils; | ||
|
@@ -48,25 +50,49 @@ | |
private $offset; | ||
/** @var int|null */ | ||
private $limit; | ||
private int $conditionsMode; | ||
private bool $extrapolateParameters; | ||
/** | ||
* @var Type[]|int[]|string[] | ||
*/ | ||
private array $parameterTypes = []; | ||
|
||
/** | ||
* @param Select $select | ||
* @param Connection $connection | ||
* @param int $conditionsMode | ||
* @param bool $extrapolateParameters | ||
*/ | ||
public function __construct(Select $select, Connection $connection) | ||
{ | ||
public function __construct( | ||
Select $select, | ||
Connection $connection, | ||
int $conditionsMode = SqlRenderInterface::CONDITION_APPLY, | ||
bool $extrapolateParameters = true | ||
) { | ||
$this->select = $select; | ||
$this->connection = $connection; | ||
$this->conditionsMode = $conditionsMode; | ||
$this->extrapolateParameters = $extrapolateParameters; | ||
} | ||
|
||
/** | ||
* The list of parameters to apply to the SQL request. | ||
* | ||
* @param array<string, string>|array<string, ValueInterface>|ArrayValueInterface $parameters | ||
* @param Type[]|string[]|int[] $types Parameter types | ||
*/ | ||
public function setParameters($parameters): void | ||
public function setParameters($parameters, array $types = []): void | ||
{ | ||
$this->parameters = $parameters; | ||
$this->parameterTypes = $types; | ||
} | ||
|
||
/** | ||
* @return array<string, string>|array<string, ValueInterface>|ArrayValueInterface | ||
*/ | ||
public function getParameters(): array | ||
Check failure on line 93 in src/Mouf/Database/QueryWriter/QueryResult.php GitHub Actions / Code Quality (7.4)
|
||
{ | ||
return $this->parameters; | ||
Check failure on line 95 in src/Mouf/Database/QueryWriter/QueryResult.php GitHub Actions / Code Quality (7.4)
|
||
} | ||
|
||
/** | ||
|
@@ -76,8 +102,8 @@ | |
*/ | ||
public function val() | ||
{ | ||
$parameters = ValueUtils::val($this->parameters); | ||
$pdoStatement = $this->connection->query($this->select->toSql($parameters, $this->connection->getDatabasePlatform()).DbHelper::getFromLimitString($this->offset, $this->limit)); | ||
$sql = $this->toSql().DbHelper::getFromLimitString($this->offset, $this->limit); | ||
$pdoStatement = $this->connection->executeQuery($sql, $this->getParametersForBind(), $this->getParameterTypesForBind()); | ||
|
||
return new ResultSet($pdoStatement); | ||
} | ||
|
@@ -91,7 +117,23 @@ | |
{ | ||
$parameters = ValueUtils::val($this->parameters); | ||
|
||
return $this->select->toSql($parameters, $this->connection->getDatabasePlatform()); | ||
return $this->select->toSql( | ||
$parameters, | ||
$this->connection->getDatabasePlatform(), | ||
0, | ||
$this->conditionsMode, | ||
$this->extrapolateParameters | ||
); | ||
} | ||
|
||
public function getParametersForBind(): array | ||
{ | ||
return $this->extrapolateParameters ? [] : $this->parameters; | ||
Check failure on line 131 in src/Mouf/Database/QueryWriter/QueryResult.php GitHub Actions / Code Quality (7.4)
|
||
} | ||
|
||
public function getParameterTypesForBind(): array | ||
{ | ||
return $this->extrapolateParameters ? [] : array_intersect_key($this->parameterTypes, $this->parameters); | ||
Check failure on line 136 in src/Mouf/Database/QueryWriter/QueryResult.php GitHub Actions / Code Quality (7.4)
|
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure that we should introduce the
mixed
return type as this would require to target newer PHP version. What's your opinin on this ?