Skip to content

Commit 29e9d6f

Browse files
author
Martin Köditz
committed
Fixed issue #25: char(1) is padded with spaces with charset UTF8
1 parent 93c8e50 commit 29e9d6f

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

ibase_query.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,10 @@ static void _php_ibase_alloc_xsqlda(XSQLDA *sqlda) /* {{{ */
947947
for (i = 0; i < sqlda->sqld; i++) {
948948
XSQLVAR *var = &sqlda->sqlvar[i];
949949

950+
if ((var->sqltype & ~1) == SQL_TEXT) {
951+
var->sqltype = SQL_VARYING | (var->sqltype & 1);
952+
}
953+
950954
switch (var->sqltype & ~1) {
951955
case SQL_TEXT:
952956
var->sqldata = safe_emalloc(sizeof(char), var->sqllen, 0);

tests/datatype_char_utf8.phpt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Check for data type CHAR(1) and UTF8
3+
--SKIPIF--
4+
<?php
5+
include("skipif.inc");
6+
?>
7+
--FILE--
8+
<?php
9+
require("interbase.inc");
10+
11+
$db = ibase_connect($test_base, );
12+
13+
ibase_query(
14+
"CREATE TABLE test_dt (
15+
v_char_utf8_1 CHAR(1) CHARACTER SET UTF8,
16+
v_char_utf8_10 CHAR(10) CHARACTER SET UTF8,
17+
v_varchar_utf8_1 VARCHAR(1) CHARACTER SET UTF8
18+
);");
19+
ibase_commit();
20+
21+
ibase_query("insert into test_dt (v_char_utf8_1, v_char_utf8_10, v_varchar_utf8_1) values ('€', ' A € ', '€')");
22+
23+
$sql = 'select * from test_dt';
24+
$query = ibase_query($sql);
25+
while(($row = ibase_fetch_assoc($query))) {
26+
var_dump($row);
27+
}
28+
29+
ibase_free_result($query);
30+
ibase_close();
31+
32+
?>
33+
--EXPECTF--
34+
array(3) {
35+
["V_CHAR_UTF8_1"]=>
36+
string(3) "€"
37+
["V_CHAR_UTF8_10"]=>
38+
string(12) " A € "
39+
["V_VARCHAR_UTF8_1"]=>
40+
string(3) "€"
41+
}

0 commit comments

Comments
 (0)