Skip to content

Commit 165d01b

Browse files
committed
Introduce few long name tests
1 parent 9627568 commit 165d01b

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed

tests/functions.inc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,25 @@ function dump_rows($q) {
9898
function dump_table_rows($table) {
9999
dump_rows(ibase_query(sprintf('SELECT * FROM "%s"', $table)));
100100
}
101+
102+
function insert_into($table, $data) {
103+
[$fields_str, $q_str] = array2sql_parts($data);
104+
return ibase_query(sprintf('INSERT INTO "%s" (%s) VALUES (%s)',
105+
$table, $fields_str, $q_str
106+
), ...array_values($data));
107+
}
108+
109+
/** @var float $v */
110+
function skip_if_fb_lt($v) {
111+
if(($cv = get_fb_version()) < $v)die("skip: Firebird version $cv < $v");
112+
}
113+
114+
/** @var float $v */
115+
function skip_if_fb_gt($v) {
116+
if(($cv = get_fb_version()) > $v)die("skip: Firebird version $cv > $v");
117+
}
118+
119+
/** @var float $v */
120+
function skip_if_fb_gte($v) {
121+
if(($cv = get_fb_version()) >= $v)die("skip: Firebird version $cv >= $v");
122+
}

tests/long_names_001.phpt

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
--TEST--
2+
Long names: Firebird 4.0 or newer
3+
--SKIPIF--
4+
<?php
5+
require_once("skipif.inc");
6+
skip_if_fb_lt(4.0);
7+
?>
8+
--FILE--
9+
<?php
10+
11+
require_once("interbase.inc");
12+
13+
// FB3: The maximum identifier length is 31 bytes
14+
// FB4: The maximum identifier length is 63 characters character set UTF8 (252 bytes)
15+
$MAX_LEN = 63;
16+
17+
function test_table(string $table){
18+
global $MAX_LEN;
19+
20+
$c = 0;
21+
22+
$fields = [
23+
'"'.str_repeat("F", $MAX_LEN).'"',
24+
'"'.str_repeat("🥰", $MAX_LEN).'"',
25+
];
26+
$fields_str = join(" INTEGER, ", $fields)." INTEGER";
27+
$create_sql = sprintf('CREATE TABLE "%s" (%s)', $table, $fields_str);
28+
29+
if(ibase_query($create_sql)){
30+
ibase_commit();
31+
} else {
32+
var_dump($create_sql);
33+
die;
34+
}
35+
36+
$data = []; foreach($fields as $f)$data[$f] = ++$c;
37+
insert_into($table, $data);
38+
print "Table:$table\n";
39+
dump_table_rows($table);
40+
}
41+
42+
(function(){
43+
global $MAX_LEN, $test_base;
44+
45+
var_dump($MAX_LEN);
46+
47+
test_table(str_repeat('T', $MAX_LEN));
48+
test_table(str_repeat('😂', $MAX_LEN));
49+
50+
print $test_base;
51+
})();
52+
53+
?>
54+
--EXPECT--
55+
Table:TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
56+
array(2) {
57+
["FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"]=>
58+
int(1)
59+
["🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰"]=>
60+
int(2)
61+
}
62+
Table:😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂
63+
array(2) {
64+
["FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"]=>
65+
int(1)
66+
["🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰"]=>
67+
int(2)
68+
}

tests/long_names_002.phpt

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
--TEST--
2+
Long names: Firebird 3.0 or older
3+
--SKIPIF--
4+
<?php
5+
require_once("skipif.inc");
6+
skip_if_fb_gt(3.0);
7+
?>
8+
--FILE--
9+
<?php
10+
11+
require_once("interbase.inc");
12+
13+
// FB 2.5, 3.0 identifier len is by byte count not character count
14+
$MAX_LEN = 31;
15+
16+
function test_table(string $table){
17+
global $MAX_LEN;
18+
19+
$c = 0;
20+
21+
$fields = [
22+
'"'.str_repeat("F", $MAX_LEN).'"',
23+
'"'.str_repeat("🥰", intdiv($MAX_LEN, 4)).'ppp"', // 7*(utf 4 bytes)+3 padding
24+
];
25+
$fields_str = join(" INTEGER, ", $fields)." INTEGER";
26+
$create_sql = sprintf('CREATE TABLE "%s" (%s)', $table, $fields_str);
27+
28+
if(ibase_query($create_sql)){
29+
ibase_commit();
30+
} else {
31+
var_dump($create_sql);
32+
die;
33+
}
34+
35+
$data = []; foreach($fields as $f)$data[$f] = ++$c;
36+
insert_into($table, $data);
37+
print "Table:$table\n";
38+
dump_table_rows($table);
39+
}
40+
41+
(function(){
42+
global $MAX_LEN;
43+
44+
test_table(str_repeat('T', $MAX_LEN));
45+
})();
46+
47+
?>
48+
--EXPECT--
49+
Table:TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
50+
array(2) {
51+
["FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"]=>
52+
int(1)
53+
["🥰🥰🥰🥰🥰🥰🥰ppp"]=>
54+
int(2)
55+
}

0 commit comments

Comments
 (0)