Skip to content

Commit

Permalink
make sqlsrv happy
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsn committed Dec 23, 2024
1 parent e344fb8 commit 24c2422
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion system/Database/SQLSRV/PreparedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ protected function parameterize(string $queryString, array $options): array

for ($c = 0; $c < $numberOfVariables; $c++) {
$this->parameters[$c] = null;
$params[] = [&$this->parameters[$c], SQLSRV_PARAM_IN, $options[$c] ?? SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR)];
if (isset($options[$c])) {
$params[] = [&$this->parameters[$c], SQLSRV_PARAM_IN, $options[$c]];
} else {
$params[] = &$this->parameters[$c];
}
}

return $params;
Expand Down
6 changes: 5 additions & 1 deletion tests/system/Database/Live/PreparedQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,11 @@ public function testInsertBinaryData(): void
$fileContent = file_get_contents(TESTPATH . '_support/Images/EXIFsamples/landscape_0.jpg');
$this->assertTrue($this->query->execute($fileContent));

$id = $this->db->insertID();
$id = $this->db->DBDriver === 'SQLSRV'
// It seems like INSERT for a prepared statement is run in the
// separate execution context even though it's part of the same session
? (int) ($this->db->query('SELECT @@IDENTITY AS insert_id')->getRow()->insert_id ?? 0)
: $this->db->insertID();
$builder = $this->db->table('type_test');

if ($this->db->DBDriver === 'Postgre') {
Expand Down

0 comments on commit 24c2422

Please sign in to comment.