Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Tests/Mysqli/MysqliPreparedStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public function testPrepareParameterKeyMappingWithSingleKey()

$this->assertEquals(
[
':search' => 0,
':search2' => 1,
':search' => [0],
':search2' => [1],
],
$parameterKeyMapping
);
Expand Down
4 changes: 2 additions & 2 deletions Tests/Sqlsrv/SqlsrvPreparedStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public function testPrepareParameterKeyMappingWithSingleKey()

$this->assertEquals(
[
':search' => 0,
':search2' => 1,
':search' => [0],
':search2' => [1],
],
$parameterKeyMapping
);
Expand Down
26 changes: 10 additions & 16 deletions src/Mysqli/MysqliStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function prepareParameterKeyMapping($sql)
$quoteChar = '';
$literal = '';
$mapping = [];
$replace = [];
$position = 0;
$matches = [];
$pattern = '/([:][a-zA-Z0-9_]+)/';

Expand Down Expand Up @@ -197,16 +197,15 @@ public function prepareParameterKeyMapping($sql)
$literal .= substr($substring, 0, $match[1]);
}

if (isset($mapping[$match[0]])) {
$mapping[$match[0]] = is_array($mapping[$match[0]]) ? $mapping[$match[0]] : [$mapping[$match[0]]];
$mapping[$match[0]][] = \count($mapping);
} else {
$mapping[$match[0]] = \count($mapping);
if (!isset($mapping[$match[0]])) {
$mapping[$match[0]] = [];
}
$endOfPlaceholder = $match[1] + strlen($match[0]);

$mapping[$match[0]][] = $position++;
$endOfPlaceholder = $match[1] + strlen($match[0]);
$beginOfNextPlaceholder = $matches[0][$i + 1][1] ?? strlen($substring);
$beginOfNextPlaceholder -= $endOfPlaceholder;
$literal .= '?' . substr($substring, $endOfPlaceholder, $beginOfNextPlaceholder);
$literal .= '?' . substr($substring, $endOfPlaceholder, $beginOfNextPlaceholder);
}
} else {
$literal .= $substring;
Expand Down Expand Up @@ -378,14 +377,9 @@ public function execute(?array $parameters = null)
foreach ($this->bindedValues as $key => &$value) {
$paramKey = $this->parameterKeyMapping[$key];

if (is_scalar($this->parameterKeyMapping[$key])) {
$params[$paramKey] =& $value;
$types[$paramKey] = $this->typesKeyMapping[$key];
} else {
foreach ($paramKey as $currentKey) {
$params[$currentKey] =& $value;
$types[$currentKey] = $this->typesKeyMapping[$key];
}
foreach ($paramKey as $currentKey) {
$params[$currentKey] =& $value;
$types[$currentKey] = $this->typesKeyMapping[$key];
}
}
} else {
Expand Down
20 changes: 7 additions & 13 deletions src/Sqlsrv/SqlsrvStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function prepareParameterKeyMapping($sql)
$quoteChar = '';
$literal = '';
$mapping = [];
$replace = [];
$position = 0;
$matches = [];
$pattern = '/([:][a-zA-Z0-9_]+)/';

Expand Down Expand Up @@ -202,17 +202,15 @@ public function prepareParameterKeyMapping($sql)
$literal .= substr($substring, 0, $match[1]);
}

if (isset($mapping[$match[0]])) {
$mapping[$match[0]] = is_array($mapping[$match[0]]) ? $mapping[$match[0]] : [$mapping[$match[0]]];
$mapping[$match[0]][] = \count($mapping);
} else {
$mapping[$match[0]] = \count($mapping);
if (!isset($mapping[$match[0]])) {
$mapping[$match[0]] = [];
}

$mapping[$match[0]][] = $position++;
$endOfPlaceholder = $match[1] + strlen($match[0]);
$beginOfNextPlaceholder = $matches[0][$i + 1][1] ?? strlen($substring);
$beginOfNextPlaceholder -= $endOfPlaceholder;
$literal .= '?' . substr($substring, $endOfPlaceholder, $beginOfNextPlaceholder);
$literal .= '?' . substr($substring, $endOfPlaceholder, $beginOfNextPlaceholder);
}
} else {
$literal .= $substring;
Expand Down Expand Up @@ -492,12 +490,8 @@ private function prepare()
if (isset($this->parameterKeyMapping[$key])) {
$paramKey = $this->parameterKeyMapping[$key];

if (is_scalar($this->parameterKeyMapping[$key])) {
$params[$paramKey] = $variable;
} else {
foreach ($paramKey as $currentKey) {
$params[$currentKey] = $variable;
}
foreach ($paramKey as $currentKey) {
$params[$currentKey] = $variable;
}
} else {
$params[] = $variable;
Expand Down