Skip to content

Commit 2fc9e76

Browse files
committed
Fix GH-8576: Bad interpretation of length when char is UTF-8
For columns of type `SQL_TEXT`, Firebird does not properly report the actual column length, but rather only the maximum column length, so for multi-byte encodings like UTF-8, such columns may have trailing spaces. We work around that by treating such columns as `SQL_VARYING` when we ask the server to describe the colum, what yields the desired results. Given that this is a work-around, and may break code which expects the results with trailing spaces, we target "master" only. Closes GH-8926.
1 parent bb5be65 commit 2fc9e76

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ PHP NEWS
1515
. Added access.suppress_path pool option to filter access log entries.
1616
(Mark Gallagher)
1717

18+
- PDO_Firebird:
19+
. Fixed GH-8576 (Bad interpretation of length when char is UTF-8). (cmb)
20+
1821
- Standard:
1922
. Fixed empty array returned by str_split on empty input. (Michael Vorisek)
2023
. Added ini_parse_quantity function to convert ini quantities shorthand

ext/pdo_firebird/firebird_statement.c

+3
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ static int firebird_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */
204204
int colname_len;
205205
char *cp;
206206

207+
if ((var->sqltype & ~1) == SQL_TEXT) {
208+
var->sqltype = SQL_VARYING | (var->sqltype & 1);
209+
}
207210
colname_len = (S->H->fetch_table_names && var->relname_length)
208211
? (var->aliasname_length + var->relname_length + 1)
209212
: (var->aliasname_length);

ext/pdo_firebird/tests/gh8576.phpt

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
GH-8576 (Bad interpretation of length when char is UTF-8)
3+
--EXTENSIONS--
4+
pdo_firebird
5+
--SKIPIF--
6+
<?php require 'skipif.inc'; ?>
7+
--FILE--
8+
<?php
9+
require 'testdb.inc';
10+
11+
$dbh->exec("CREATE TABLE gh8576 (name CHAR(1) CHARACTER SET UTF8)");
12+
$dbh->exec("INSERT INTO gh8576 VALUES ('A')");
13+
$stmt = $dbh->query("SELECT * FROM gh8576");
14+
var_dump($stmt->fetchAll());
15+
?>
16+
--EXPECT--
17+
array(1) {
18+
[0]=>
19+
array(2) {
20+
["NAME"]=>
21+
string(1) "A"
22+
[0]=>
23+
string(1) "A"
24+
}
25+
}
26+
--CLEAN--
27+
<?php
28+
require 'testdb.inc';
29+
$dbh->exec("DROP TABLE gh8576");
30+
?>

0 commit comments

Comments
 (0)