Skip to content

Commit 4560a51

Browse files
icewind1991backportbot[bot]
authored andcommitted
fix: fix oci string length with empty strings
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent e75294e commit 4560a51

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/private/DB/QueryBuilder/FunctionBuilder/OCIFunctionBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
8080
public function octetLength($field, $alias = ''): IQueryFunction {
8181
$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
8282
$quotedName = $this->helper->quoteColumnName($field);
83-
return new QueryFunction('LENGTHB(' . $quotedName . ')' . $alias);
83+
return new QueryFunction('COALESCE(LENGTHB(' . $quotedName . '), 0)' . $alias);
8484
}
8585

8686
public function charLength($field, $alias = ''): IQueryFunction {
8787
$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
8888
$quotedName = $this->helper->quoteColumnName($field);
89-
return new QueryFunction('LENGTH(' . $quotedName . ')' . $alias);
89+
return new QueryFunction('COALESCE(LENGTH(' . $quotedName . '), 0)' . $alias);
9090
}
9191
}

tests/lib/DB/QueryBuilder/FunctionBuilderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ public function testCharLength(string $str, int $bytes): void {
370370
$result = $query->execute();
371371
$column = $result->fetchOne();
372372
$result->closeCursor();
373+
$this->assertNotNull($column);
373374
$this->assertEquals($bytes, $column);
374375
}
375376

0 commit comments

Comments
 (0)