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