cvs: pear /MDB2/tests MDB2_usage_testcase.php

From: Date: Sat, 19 Aug 2006 22:13:30 +0000
Subject: cvs: pear /MDB2/tests MDB2_usage_testcase.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-41727@lists.php.net to get a copy of this message
justinpatrin Sat Aug 19 22:13:30 2006 UTC Modified files: /pear/MDB2/tests MDB2_usage_testcase.php Log: Add a test case for updating LOBs http://cvs.php.net/viewvc.cgi/pear/MDB2/tests/MDB2_usage_testcase.php?r1=1.75&r2=1.76&diff_format=u Index: pear/MDB2/tests/MDB2_usage_testcase.php diff -u pear/MDB2/tests/MDB2_usage_testcase.php:1.75 pear/MDB2/tests/MDB2_usage_testcase.php:1.76 --- pear/MDB2/tests/MDB2_usage_testcase.php:1.75 Mon Aug 14 07:15:32 2006 +++ pear/MDB2/tests/MDB2_usage_testcase.php Sat Aug 19 22:13:30 2006 @@ -41,7 +41,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: MDB2_usage_testcase.php,v 1.75 2006/08/14 07:15:32 lsmith Exp $ +// $Id: MDB2_usage_testcase.php,v 1.76 2006/08/19 22:13:30 justinpatrin Exp $ require_once 'MDB2_testcase.php'; @@ -1290,6 +1290,103 @@ $result->free(); } + function testLOBUpdate() { + if (!$this->supported('LOBs')) { + $this->assertTrue(false, '"LOBs" is not supported'); + return; + } + + $query = 'INSERT INTO files (ID, document, picture) VALUES (1, ?, ?)'; + $stmt = $this->db->prepare($query, array('clob', 'blob'), MDB2_PREPARE_MANIP, array('document', 'picture')); + + $character_lob = ''; + $binary_lob = ''; + + for ($i = 0; $i < 1000; $i++) { + for ($code = 32; $code <= 127; ++$code) { + $character_lob .= chr($code); + } + for ($code = 0; $code <= 255; ++$code) { + $binary_lob .= chr($code); + } + } + + $stmt->bindParam(0, $character_lob); + $stmt->bindParam(1, $binary_lob); + + $result = $stmt->execute(); + + if (PEAR::isError($result)) { + $this->assertTrue(false, 'Error executing prepared query: '.$result->getUserInfo()); + } + + $stmt->free(); + + $query = 'UPDATE files SET document = ?, picture = ? WHERE ID = 1'; + $stmt = $this->db->prepare($query, array('clob', 'blob'), MDB2_PREPARE_MANIP, array('document', 'picture')); + + $character_lob = ''; + $binary_lob = ''; + + for ($i = 0; $i < 999; $i++) { + for ($code = 127; $code >= 32; --$code) { + $character_lob .= chr($code); + } + for ($code = 255; $code >= 0; --$code) { + $binary_lob .= chr($code); + } + } + + $stmt->bindParam(0, $character_lob); + $stmt->bindParam(1, $binary_lob); + + $result = $stmt->execute(); + + if (PEAR::isError($result)) { + $this->assertTrue(false, 'Error executing prepared query: '.$result->getUserInfo()); + } + + $stmt->free(); + + $result =& $this->db->query('SELECT document, picture FROM files WHERE id = 1', array('clob', 'blob')); + if (PEAR::isError($result)) { + $this->assertTrue(false, 'Error selecting from files'.$result->getMessage()); + } + + $this->assertTrue($result->valid(), 'The query result seem to have reached the end of result too soon.'); + + $row = $result->fetchRow(); + $clob = $row[0]; + if (!PEAR::isError($clob) && is_resource($clob)) { + $value = ''; + while (!feof($clob)) { + $data = fread($clob, 8192); + $this->assertTrue(strlen($data) >= 0, 'Could not read CLOB'); + $value.= $data; + } + $this->db->datatype->destroyLOB($clob); + $this->assertEquals($character_lob, $value, 'Retrieved character LOB value is different from what was stored'); + } else { + $this->assertTrue(false, 'Error retrieving CLOB result'); + } + + $blob = $row[1]; + if (!PEAR::isError($blob) && is_resource($blob)) { + $value = ''; + while (!feof($blob)) { + $data = fread($blob, 8192); + $this->assertTrue(strlen($data) >= 0, 'Could not read BLOB'); + $value.= $data; + } + + $this->db->datatype->destroyLOB($blob); + $this->assertEquals($binary_lob, $value, 'Retrieved binary LOB value is different from what was stored'); + } else { + $this->assertTrue(false, 'Error retrieving BLOB result'); + } + $result->free(); + } + /** * Test retrieval of result metadata * @@ -1378,7 +1475,7 @@ $field = next($fields); } - // leave the case as-is + // leave the case as-is $this->db->setOption('portability', MDB2_PORTABILITY_NONE); $fields = array('User_Name', 'UseR_PassWord'); $query = 'SELECT '. implode(',', $fields).' FROM users';

« previous php.pear.cvs (#41727) next »