xref: /PHP-8.3/ext/pdo_odbc/tests/max_columns.phpt (revision 74859783)
1--TEST--
2PDO ODBC varying character with max/no length
3--EXTENSIONS--
4pdo_odbc
5--SKIPIF--
6<?php
7require 'ext/pdo/tests/pdo_test.inc';
8PDOTest::skip();
9?>
10--FILE--
11<?php
12require 'ext/pdo/tests/pdo_test.inc';
13$db = PDOTest::test_factory('ext/pdo_odbc/tests/common.phpt');
14$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
15
16if (false === $db->exec('CREATE TABLE TEST (id INT NOT NULL PRIMARY KEY, data varchar(max))')) {
17    if (false === $db->exec('CREATE TABLE TEST (id INT NOT NULL PRIMARY KEY, data longtext)')) {
18        if (false === $db->exec('CREATE TABLE TEST (id INT NOT NULL PRIMARY KEY, data CLOB)')) {
19            die("BORK: don't know how to create a long column here:\n" . implode(", ", $db->errorInfo()));
20        }
21    }
22}
23
24$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
25
26$sizes = array(32, 64, 128, 253, 254, 255, 256, 257, 258, 512, 1024, 2048, 3998, 3999, 4000);
27
28$db->beginTransaction();
29$insert = $db->prepare('INSERT INTO TEST VALUES (?, ?)');
30foreach ($sizes as $num) {
31    $insert->execute(array($num, str_repeat('i', $num)));
32}
33$insert = null;
34$db->commit();
35
36foreach ($db->query('SELECT id, data from TEST') as $row) {
37    $expect = str_repeat('i', $row[0]);
38    if (strcmp($expect, $row[1])) {
39        echo "Failed on size $row[id]:\n";
40        printf("Expected %d bytes, got %d\n", strlen($expect), strlen($row['data']));
41        echo bin2hex($expect) . "\n";
42        echo bin2hex($row['data']) . "\n";
43    }
44}
45
46echo "Finished\n";
47?>
48--EXPECT--
49Finished
50