Skip to content

Commit 24c2422

Browse files
committed
make sqlsrv happy
1 parent e344fb8 commit 24c2422

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

system/Database/SQLSRV/PreparedQuery.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ protected function parameterize(string $queryString, array $options): array
131131

132132
for ($c = 0; $c < $numberOfVariables; $c++) {
133133
$this->parameters[$c] = null;
134-
$params[] = [&$this->parameters[$c], SQLSRV_PARAM_IN, $options[$c] ?? SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR)];
134+
if (isset($options[$c])) {
135+
$params[] = [&$this->parameters[$c], SQLSRV_PARAM_IN, $options[$c]];
136+
} else {
137+
$params[] = &$this->parameters[$c];
138+
}
135139
}
136140

137141
return $params;

tests/system/Database/Live/PreparedQueryTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,11 @@ public function testInsertBinaryData(): void
284284
$fileContent = file_get_contents(TESTPATH . '_support/Images/EXIFsamples/landscape_0.jpg');
285285
$this->assertTrue($this->query->execute($fileContent));
286286

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

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

0 commit comments

Comments
 (0)