cvs: php4 /pear DB.php /pear/DB common.php ibase.php mysql.php /pear/DB/tests/odbc 001.phpt skipif.inc /pear/XML Parser.php /pear/XML/tests
001.phpt 002.phpt 003.phpt 004.phpt 005.phpt parser3.i test.xml

From: Date: Wed, 06 Dec 2000 02:53:17 +0000
Subject: cvs: php4 /pear DB.php /pear/DB common.php ibase.php mysql.php /pear/DB/tests/odbc 001.phpt skipif.inc /pear/XML Parser.php /pear/XML/tests
001.phpt 002.phpt 003.phpt 004.phpt 005.phpt parser3.i test.xml
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-2965@lists.php.net to get a copy of this message
ssb Tue Dec 5 18:53:17 2000 EDT Added files: /php4/pear/DB/tests/odbc 001.phpt skipif.inc /php4/pear/XML/tests 001.phpt 002.phpt 003.phpt 004.phpt 005.phpt test.xml Removed files: /php4/pear/XML/tests parser3.i Modified files: /php4/pear DB.php /php4/pear/DB common.php ibase.php mysql.php /php4/pear/XML Parser.php Log: * cleanup

Index: php4/pear/DB.php diff -u php4/pear/DB.php:1.38 php4/pear/DB.php:1.39 --- php4/pear/DB.php:1.38 Mon Dec 4 23:00:57 2000 +++ php4/pear/DB.php Tue Dec 5 18:53:14 2000 @@ -17,7 +17,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: DB.php,v 1.38 2000/12/05 07:00:57 ssb Exp $ +// $Id: DB.php,v 1.39 2000/12/06 02:53:14 ssb Exp $ // // Database independent query interface. // @@ -535,7 +535,7 @@ */ function free() { $err = $this->dbh->freeResult($this->result); - if( DB::isError($err)) { + if(DB::isError($err)) { return $err; } $this->result = false; Index: php4/pear/DB/common.php diff -u php4/pear/DB/common.php:1.27 php4/pear/DB/common.php:1.28 --- php4/pear/DB/common.php:1.27 Mon Dec 4 10:28:17 2000 +++ php4/pear/DB/common.php Tue Dec 5 18:53:15 2000 @@ -20,13 +20,13 @@ // Base class for DB implementations. // - /** - * DB_common is a base class for DB implementations, and should be - * inherited by all such. - */ +/** + * DB_common is a base class for DB implementations, and should be + * inherited by all such. + */ - class DB_common - { +class DB_common +{ // {{{ properties var $features; // assoc of capabilities for this DB implementation @@ -47,18 +47,17 @@ function toString() { - $info = get_class( $this ); + $info = get_class($this); + + $info .= ": (phptype=" . $this->phptype . + ", dbsyntax=" . $this->dbsyntax . + ")"; - $info .= ": (phptype=" . $this->phptype . - ", dbsyntax=" . $this->dbsyntax . - ")"; - - if( $this->connection ) - { - $info .= " [connected]"; - } + if ($this->connection) { + $info .= " [connected]"; + } - return $info; + return $info; } // }}} @@ -66,9 +65,9 @@ function DB_common() { - $this->features = array(); - $this->errorcode_map = array(); - $this->fetchmode = DB_FETCHMODE_ORDERED; + $this->features = array(); + $this->errorcode_map = array(); + $this->fetchmode = DB_FETCHMODE_ORDERED; } // }}} @@ -83,9 +82,9 @@ * @return string the quoted string */ - function quoteString( $string ) + function quoteString($string) { - return str_replace( "'", "\'", $string ); + return str_replace("'", "\'", $string); } // }}} @@ -100,9 +99,9 @@ * @return bool whether this DB implementation supports $feature */ - function provides( $feature ) + function provides($feature) { - return $this->features[ $feature ]; + return $this->features[$feature]; } // }}} @@ -120,18 +119,17 @@ * implementation has no mapping for the given error code. */ - function errorCode( $nativecode ) + function errorCode($nativecode) { - if( $this->errorcode_map[ $nativecode ] ) - { - return $this->errorcode_map[ $nativecode ]; - } - - //php_error(E_WARNING, get_class($this)."::errorCode: no mapping for $nativecode"); - // Fall back to DB_ERROR if there was no mapping. Ideally, - // this should never happen. + if ($this->errorcode_map[$nativecode]) { + return $this->errorcode_map[$nativecode]; + } + + //php_error(E_WARNING, get_class($this)."::errorCode: no mapping for $nativecode"); + // Fall back to DB_ERROR if there was no mapping. Ideally, + // this should never happen. - return $this->raiseError( DB_ERROR, false, false, false, $nativecode ); + return $this->raiseError(DB_ERROR, false, false, false, $nativecode); } // }}} @@ -147,9 +145,9 @@ * if the error code was unknown */ - function errorMessage( $dbcode ) + function errorMessage($dbcode) { - return DB::errorMessage( $this->errorcode_map[ $dbcode ] ); + return DB::errorMessage($this->errorcode_map[$dbcode]); } // }}} @@ -160,42 +158,34 @@ * */ - function &raiseError( $code = DB_ERROR, $mode = false, $level = false, $debuginfo = false, $nativecode = false ) + function &raiseError($code = DB_ERROR, $mode = false, $level = false, + $debuginfo = false, $nativecode = false) { - if( !$mode ) - { - $mode = $this->error_mode; - } - - if( $mode == PEAR_ERROR_CALLBACK ) - { - if( !is_string( $level ) && - !( is_array( $level ) && sizeof( $level ) == 2 && - is_object( $level[ 0 ] ) && is_string( $level[ 1 ] ) ) ) - { - $level = $this->error_callback; - } - } - - else - { - if( !$level ) - { - $level = $this->error_level; - } - } - - if( !$debuginfo ) - { - $debuginfo = $this->last_query; - } - - if( $nativecode ) - { - $debuginfo .= " [nativecode=$nativecode]"; - } + if (!$mode) { + $mode = $this->error_mode; + } + + if ($mode == PEAR_ERROR_CALLBACK) { + if (!is_string($level) && + !(is_array($level) && sizeof($level) == 2 && + is_object($level[0]) && is_string($level[1]))) { + $level = $this->error_callback; + } + } else { + if (!$level) { + $level = $this->error_level; + } + } + + if (!$debuginfo) { + $debuginfo = $this->last_query; + } + + if ($nativecode) { + $debuginfo .= " [nativecode=$nativecode]"; + } - return new DB_Error( $code, $mode, $level, $debuginfo ); + return new DB_Error($code, $mode, $level, $debuginfo); } // }}} @@ -228,49 +218,38 @@ * @see PEAR_ERROR_CALLBACK */ - function setErrorHandling( $mode, $options = false ) + function setErrorHandling($mode, $options = false) { - switch( $mode ) - { - case PEAR_ERROR_RETURN: - case PEAR_ERROR_PRINT: - case PEAR_ERROR_TRIGGER: - case PEAR_ERROR_DIE: $this->error_mode = $mode; - - if( !$options ) - { - $this->error_level = E_USER_NOTICE; - } - - else - { - $this->error_level = $options; - } - - break; - - case PEAR_ERROR_CALLBACK: $this->error_mode = $mode; - - if( is_string( $options ) || - ( is_array( $options ) && sizeof( $options ) == 2 && - is_object( $options[ 0 ] ) && is_string( $options[ 1 ] ) ) ) - { - $this->error_callback = $options; - } - - else - { - trigger_error( E_USER_WARNING, "invalid error callback" ); - } - - $this->error_level = PEAR_ERROR_RETURN; - - break; - - default: trigger_error( E_USER_WARNING, "invalid error mode" ); - - break; - } + switch ($mode) { + case PEAR_ERROR_RETURN: + case PEAR_ERROR_PRINT: + case PEAR_ERROR_TRIGGER: + case PEAR_ERROR_DIE: + $this->error_mode = $mode; + + if (!$options) { + $this->error_level = E_USER_NOTICE; + } else { + $this->error_level = $options; + } + break; + + case PEAR_ERROR_CALLBACK: + $this->error_mode = $mode; + if (is_string($options) || + (is_array($options) && sizeof($options) == 2 && + is_object($options[0]) && is_string($options[1]))) { + $this->error_callback = $options; + } else { + trigger_error(E_USER_WARNING, "invalid error callback"); + } + $this->error_level = PEAR_ERROR_RETURN; + break; + + default: + trigger_error(E_USER_WARNING, "invalid error mode"); + break; + } } // }}} @@ -289,17 +268,16 @@ * @see DB_FETCHMODE_FLIPPED */ - function setFetchMode( $fetchmode ) + function setFetchMode($fetchmode) { - switch( $fetchmode ) - { - case DB_FETCHMODE_ORDERED: - case DB_FETCHMODE_ASSOC: $this->fetchmode = $fetchmode; - - break; - - default: return $this->raiseError("invalid get mode"); - } + switch ($fetchmode) { + case DB_FETCHMODE_ORDERED: + case DB_FETCHMODE_ASSOC: + $this->fetchmode = $fetchmode; + break; + default: + return $this->raiseError("invalid get mode"); + } } // }}} @@ -310,33 +288,30 @@ * PostgreSQL, this is emulated. */ - function prepare( $query ) + function prepare($query) { - $tokens = split( "[\&\?]", $query ); - $token = 0; - $types = array(); - - for( $i = 0; $i < strlen( $query ); $i++ ) - { - switch( $query[ $i ] ) - { - case "?": $types[ $token++ ] = DB_PARAM_SCALAR; - + $tokens = split("[\&\?]", $query); + $token = 0; + $types = array(); + + for ($i = 0; $i < strlen( $query ); $i++) { + switch ($query[ $i ]) { + case "?": + $types[$token++] = DB_PARAM_SCALAR; break; - - case "&": $types[ $token++ ] = DB_PARAM_OPAQUE; - + case "&": + $types[$token++] = DB_PARAM_OPAQUE; break; + } } - } - $this->prepare_tokens[] = &$tokens; - end( $this->prepare_tokens ); + $this->prepare_tokens[] = &$tokens; + end($this->prepare_tokens); - $k = key( $this->prepare_tokens ); - $this->prepare_types[ $k ] = $types; + $k = key($this->prepare_tokens); + $this->prepare_types[$k] = $types; - return $k; + return $k; } // }}} @@ -347,73 +322,56 @@ * prepare/execute. A DB error code is returned on failure. */ - function execute_emulate_query( $stmt, $data = false ) + function execute_emulate_query($stmt, $data = false) { - $p = &$this->prepare_tokens; - $stmt = (int)$this->prepare_maxstmt++; + $p = &$this->prepare_tokens; + $stmt = (int)$this->prepare_maxstmt++; + + if (!isset($this->prepare_tokens[$stmt]) || + !is_array($this->prepare_tokens[$stmt]) || + !sizeof($this->prepare_tokens[$stmt])) { + return $this->raiseError(DB_ERROR_INVALID); + } + + $qq = &$this->prepare_tokens[$stmt]; + $qp = sizeof($qq) - 1; + + if ((!$data && $qp > 0) || + (!is_array($data) && $qp > 1) || + (is_array($data) && $qp > sizeof($data))) { + return $this->raiseError(DB_ERROR_NEED_MORE_DATA); + } + + $realquery = $qq[0]; + + for ($i = 0; $i < $qp; $i++) { + if ($this->prepare_types[$stmt][$i] == DB_PARAM_OPAQUE) { + if (is_array($data)) { + $fp = fopen($data[$i], "r"); + } else { + $fp = fopen($data, "r"); + } + + $pdata = ""; + + if ($fp) { + while (($buf = fread($fp, 4096)) != false) { + $pdata .= $buf; + } + } + } else { + if (is_array($data)) { + $pdata = &$data[$i]; + } else { + $pdata = &$data; + } + } - if( !isset( $this->prepare_tokens[ $stmt ] ) || - !is_array( $this->prepare_tokens[ $stmt ] ) || - !sizeof( $this->prepare_tokens[ $stmt ] ) ) - { - return $this->raiseError( DB_ERROR_INVALID ); - } - - $qq = &$this->prepare_tokens[ $stmt ]; - $qp = sizeof($qq) - 1; - - if( ( !$data && $qp > 0 ) || - ( !is_array( $data ) && $qp > 1 ) || - ( is_array( $data ) && $qp > sizeof( $data ) ) ) - { - return $this->raiseError( DB_ERROR_NEED_MORE_DATA ); - } - - $realquery = $qq[ 0 ]; - - for( $i = 0; $i < $qp; $i++ ) - { - if( $this->prepare_types[ $stmt ][ $i ] == DB_PARAM_OPAQUE ) - { - if( is_array( $data ) ) - { - $fp = fopen( $data[ $i ], "r" ); - } - - else - { - $fp = fopen( $data, "r" ); - } - - $pdata = ""; - - if( $fp ) - { - while( ( $buf = fread( $fp, 4096 ) ) != false ) - { - $pdata .= $buf; - } - } - } - - else - { - if( is_array( $data ) ) - { - $pdata = &$data[ $i ]; - } - - else - { - $pdata = &$data; - } - } - - $realquery .= "'" . $this->quoteString( $pdata ) . "'"; - $realquery .= $qq[ $i + 1 ]; - } + $realquery .= "'" . $this->quoteString($pdata) . "'"; + $realquery .= $qq[$i + 1]; + } - return $realquery; + return $realquery; } // }}} @@ -430,17 +388,13 @@ function executeMultiple( $stmt, &$data ) { - for( $i = 0; $i < sizeof( $data ); $i++ ) - { - $res = $this->execute( $stmt, $data[ $i ] ); - - if( DB::isError( $res ) ) - { - return $res; + for($i = 0; $i < sizeof( $data ); $i++) { + $res = $this->execute($stmt, $data[$i]); + if (DB::isError($res)) { + return $res; + } } - } - - return DB_OK; + return DB_OK; } // }}} @@ -457,46 +411,37 @@ * @access public */ - function &getOne( $query, $params = array() ) + function &getOne($query, $params = array()) { - if( sizeof( $params ) > 0 ) - { - $sth = $this->prepare( $query ); + if (sizeof($params) > 0) { + $sth = $this->prepare($query); - if( DB::isError( $sth ) ) - { - return $sth; + if (DB::isError($sth)) { + return $sth; + } + $res = $this->execute($sth, $params); + } else { + $res = $this->simpleQuery($query); } - - $res = $this->execute( $sth, $params ); - } - else - { - $res = $this->simpleQuery( $query ); - } - - if( DB::isError( $res ) ) - { - return $res; - } + if (DB::isError($res)) { + return $res; + } - $row = $this->fetchRow( $res, DB_FETCHMODE_ORDERED ); + $row = $this->fetchRow($res, DB_FETCHMODE_ORDERED); - if( DB::isError( $row ) ) - { - return $row; - } + if (DB::isError($row)) { + return $row; + } - $ret = &$row[ 0 ]; - $this->freeResult( $res ); + $ret = &$row[0]; + $this->freeResult($res); - if( isset( $sth ) ) - { - $this->freeResult( $sth ); - } + if (isset($sth)) { + $this->freeResult($sth); + } - return $ret; + return $ret; } // }}} @@ -512,50 +457,40 @@ * 0, or a DB error code. */ - function &getRow( $query, $fetchmode = DB_FETCHMODE_DEFAULT, $params = array() ) + function &getRow($query, $fetchmode = DB_FETCHMODE_DEFAULT, + $params = array()) { - if( $fetchmode == DB_FETCHMODE_DEFAULT ) - { - $fetchmode = $this->fetchmode; - } + if ($fetchmode == DB_FETCHMODE_DEFAULT) { + $fetchmode = $this->fetchmode; + } - if( sizeof( $params ) > 0 ) - { - $sth = $this->prepare( $query ); + if (sizeof($params) > 0) { + $sth = $this->prepare( $query ); + if (DB::isError($sth)) { + return $sth; + } + $res = $this->execute($sth, $params); + } else { + $res = $this->simpleQuery($query); + } - if( DB::isError( $sth ) ) - { - return $sth; + if (DB::isError($res)) { + return $res; } - $res = $this->execute( $sth, $params ); - } + $row = $this->fetchRow($res, $fetchmode); - else - { - $res = $this->simpleQuery( $query ); - } + if (DB::isError($row)) { + return $row; + } - if( DB::isError( $res ) ) - { - return $res; - } + $this->freeResult($res); - $row = $this->fetchRow( $res, $fetchmode ); + if (isset($sth)) { + $this->freeResult($sth); + } - if( DB::isError( $row ) ) - { return $row; - } - - $this->freeResult( $res ); - - if( isset( $sth ) ) - { - $this->freeResult( $sth ); - } - - return $row; } // }}} @@ -576,52 +511,43 @@ * row at index 0, or a DB error code. */ - function &getCol( $query, $col = 0, $params = array() ) + function &getCol($query, $col = 0, $params = array()) { - if( sizeof( $params ) > 0 ) - { - $sth = $this->prepare( $query ); + if (sizeof($params) > 0) { + $sth = $this->prepare($query); - if( DB::isError( $sth ) ) - { - return $sth; - } + if (DB::isError($sth)) { + return $sth; + } - $res = $this->execute( $sth, $params ); - } + $res = $this->execute($sth, $params); + } else { + $res = $this->simpleQuery($query); + } - else - { - $res = $this->simpleQuery( $query ); - } + if (DB::isError($res)) { + return $res; + } - if( DB::isError( $res ) ) - { - return $res; - } + $fetchmode = is_int($col) ? DB_FETCHMODE_ORDERED : DB_FETCHMODE_ASSOC; + $ret = array(); - $fetchmode = is_int($col) ? DB_FETCHMODE_ORDERED : DB_FETCHMODE_ASSOC; - $ret = array(); + while ($row = $this->fetchRow($res, $fetchmode)) { + if (DB::isError($row)) { + $ret = $row; + break; + } - while( $row = $this->fetchRow( $res, $fetchmode ) ) - { - if( DB::isError( $row ) ) - { - $ret = $row; - break; + $ret[] = $row[$col]; } - - $ret[] = $row[ $col ]; - } - $this->freeResult( $res ); + $this->freeResult($res); - if( isset( $sth ) ) - { - $this->freeResult( $sth ); - } + if (isset($sth)) { + $this->freeResult($sth); + } - return $ret; + return $ret; } // }}} @@ -661,83 +587,69 @@ * '1' => 'one', * '2' => 'two', * '3' => 'three', - * ) + * ) * * ...while the call getAssoc('SELECT id,text,date FROM mydate') returns: * array( * '1' => array('one', '944679408'), * '2' => array('two', '944679408'), * '3' => array('three', '944679408') - * ) + * ) * * Keep in mind that database functions in PHP usually return string * values for results regardless of the database's internal type. */ - function &getAssoc( $query, $force_array = false, $params = array() ) + function &getAssoc($query, $force_array = false, $params = array()) { - if( sizeof( $params ) > 0 ) - { - $sth = $this->prepare( $query ); + if (sizeof($params) > 0) { + $sth = $this->prepare($query); - if( DB::isError( $sth ) ) - { - return $sth; - } - - $res = $this->execute( $sth, $params ); - } - - else - { - $res = $this->simpleQuery( $query ); - } - - if( DB::isError( $res ) ) - { - return $res; - } - - $cols = $this->numCols( $res ); + if (DB::isError($sth)) { + return $sth; + } - if( $cols < 2 ) - { - return $this->raiseError( DB_ERROR_TRUNCATED ); - } + $res = $this->execute($sth, $params); + } else { + $res = $this->simpleQuery($query); + } - $results = array(); + if (DB::isError($res)) { + return $res; + } - if( $cols > 2 || $force_array ) - { - // return array values - // XXX this part can be optimized - while( ( $row = $this->fetchRow( $res, DB_FETCHMODE_ORDERED ) ) && !DB::isError( $row ) ) - { - reset($row); + $cols = $this->numCols($res); - // we copy the row of data into a new array - // to get indices running from 0 again - $results[ $row[ 0 ] ] = array_slice( $row, 1 ); + if ($cols < 2) { + return $this->raiseError(DB_ERROR_TRUNCATED); } - } + + $results = array(); - else - { - // return scalar values - while( ( $row = $this->fetchRow( $res ) ) && !DB::isError( $row ) ) - { - $results[ $row[ 0 ] ] = $row[ 1 ]; + if ($cols > 2 || $force_array) { + // return array values + // XXX this part can be optimized + while (($row = $this->fetchRow($res, DB_FETCHMODE_ORDERED)) && + !DB::isError($row)) { + reset($row); + // we copy the row of data into a new array + // to get indices running from 0 again + $results[$row[0]] = array_slice($row, 1); + } + } else { + // return scalar values + while (($row = $this->fetchRow($res)) && !DB::isError($row)) { + $results[$row[0]] = $row[1]; + } } - } - $this->freeResult( $res ); + $this->freeResult($res); - if( isset( $sth ) ) - { - $this->freeResult( $sth ); - } + if (isset($sth)) { + $this->freeResult($sth); + } - return $results; + return $results; } // }}} @@ -751,122 +663,52 @@ * @return array an nested array, or a DB error */ - function &getAll( $query, $fetchmode = DB_FETCHMODE_DEFAULT, $params = array() ) + function &getAll($query, $fetchmode = DB_FETCHMODE_DEFAULT, + $params = array()) { - if( $fetchmode == DB_FETCHMODE_DEFAULT ) - { - $fetchmode = $this->fetchmode; - } - - if( sizeof( $params ) > 0 ) - { - $sth = $this->prepare( $query ); - - if( DB::isError( $sth ) ) - { - return $sth; + if ($fetchmode == DB_FETCHMODE_DEFAULT) { + $fetchmode = $this->fetchmode; } - $res = $this->execute( $sth, $params ); - } + if (sizeof($params) > 0) { + $sth = $this->prepare($query); - else - { - $res = $this->simpleQuery( $query ); - } - - if( DB::isError( $res ) ) - { - return $res; - } - - $results = array(); + if (DB::isError($sth)) { + return $sth; + } - while( ( $row = $this->fetchRow( $res, $fetchmode ) ) && !DB::isError( $row ) ) - { - if( $fetchmode & DB_FETCHMODE_FLIPPED ) - { - foreach( $row as $key => $val ) - { - $results[ $key][] = $val; - } + $res = $this->execute($sth, $params); + } else { + $res = $this->simpleQuery($query); } - else - { - $results[] = $row; + if (DB::isError($res)) { + return $res; } - } - $this->freeResult( $res ); + $results = array(); - if( isset( $sth ) ) - { - $this->freeResult( $sth ); - } - - return $results; - } - - // }}} - // {{{ nextid() - - /** - * Returns the next number of a given sequence. - * - * This method needs the following table in the used database: - * - * CREATE TABLE db_sequence ( - * seq_name varchar(127) NOT NULL, - * nextid int(10) unsigned DEFAULT '0' NOT NULL, - * PRIMARY KEY (seq_name) - * ); - * - * @param string $seq_name name of the sequence - * @return int next number in $sequence - * @access private - * @author Sebastian Bergmann <sbergmann@php.net> - */ - - function nextid( $seq_name ) - { - // lock db_sequence table - if( $this->lock( $this->seq_table ) ) - { - // check, if this sequence already exists - $result = $this->query( "select nextid from " . $this->seq_table . " where seq_name = '$seq_name'" ); - - // sequence already exists - if( is_array( $row = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) ) - { - // get next id for this sequence - $id = $row[ "nextid" ] + 1; - - // update next id for this sequence in db_sequence table - $result = $this->query( "update " . $this->seq_table . " set nextid = nextid + 1 where seq_name = '$seq_name'" ); + while (($row = $this->fetchRow($res, $fetchmode)) && + !DB::isError($row)) { + if ($fetchmode & DB_FETCHMODE_FLIPPED) { + foreach ($row as $key => $val) { + $results[$key][] = $val; + } + } else { + $results[] = $row; + } } - // sequence doesn't exist, create it - else - { - // init sequence's id to 1 - $id = 1; + $this->freeResult($res); - // create entry in db_sequence table - $result = $this->query( "insert into " . $this->seq_table . " values( '$seq_name', '$id' )" ); + if (isset($sth)) { + $this->freeResult($sth); } - } - - else - { - // table locking failed - return false; - } - - // return next id for requested sequence - return $id; + + return $results; } // }}} - } +} + ?> Index: php4/pear/DB/ibase.php diff -u php4/pear/DB/ibase.php:1.9 php4/pear/DB/ibase.php:1.10 --- php4/pear/DB/ibase.php:1.9 Fri Dec 1 06:58:10 2000 +++ php4/pear/DB/ibase.php Tue Dec 5 18:53:15 2000 @@ -16,7 +16,7 @@ // | Authors: Sterling Hughes <sterling@php.net> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.9 2000/12/01 14:58:10 sterling Exp $ +// $Id: ibase.php,v 1.10 2000/12/06 02:53:15 ssb Exp $ // // Database independent query interface definition for PHP's Interbase // extension. @@ -28,8 +28,6 @@ var $connection; var $phptype, $dbsyntax; - var $prepare_tokens = array(); - var $prepare_types = array(); function DB_ibase() { $this->phptype = 'ibase'; Index: php4/pear/DB/mysql.php diff -u php4/pear/DB/mysql.php:1.31 php4/pear/DB/mysql.php:1.32 --- php4/pear/DB/mysql.php:1.31 Mon Dec 4 23:00:57 2000 +++ php4/pear/DB/mysql.php Tue Dec 5 18:53:15 2000 @@ -464,61 +464,6 @@ } // }}} - // {{{ lock() - - function lock($table, $mode = "write") { - // build query string to lock tables - $query = "lock tables "; - - // parameter $table is an array - parse it - if (is_array($table)) { - // walk through array - while (list($key, $value) = each($table)) { - if ($key == "read" && $key != 0) { - $query .= "$value read, "; - } else { - $query .= "$value $mode, "; - } - } - - $query = substr($query, 0, -2); - } - // parameter $table is just one table name - else { - $query .= "$table $mode"; - } - - // perform query to lock table(s) - $result = mysql_query($query, $this->connection); - - // check, if query succeeded - if (!$result) { - // query failed - return false; - } - - // query succeeded - return true; - } - - // }}} - // {{{ unlock() - - function unlock() { - // perform query to unlock tables - $result = mysql_query("unlock tables", $this->connection); - - // check, if query succeeded - if (!$result) { - // query failed - return false; - } - - // query succeeded - return true; - } - - // }}} // {{{ nextId() /** Index: php4/pear/XML/Parser.php diff -u php4/pear/XML/Parser.php:1.3 php4/pear/XML/Parser.php:1.4 --- php4/pear/XML/Parser.php:1.3 Tue Sep 26 00:33:19 2000 +++ php4/pear/XML/Parser.php Tue Dec 5 18:53:15 2000 @@ -1,4 +1,22 @@ <?php +// +// +----------------------------------------------------------------------+ +// | PHP version 4.0 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group | +// +----------------------------------------------------------------------+ +// | This source file is subject to version 2.02 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available at through the world-wide-web at | +// | http://www.php.net/license/2_02.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Authors: Stig Bakken <ssb@fast.no> | +// | | +// +----------------------------------------------------------------------+ +// require_once "PEAR.php"; @@ -9,47 +27,92 @@ - mixing character encodings - a test using all expat handlers - options (folding, output charset) +- different parsing modes - */ +*/ +/** + * XML Parser class. This is an XML parser based on PHP's "xml" extension, + * based on the bundled expat library. + * + * @author Stig Bakken <ssb@fast.no> + * + */ class XML_Parser extends PEAR { + // {{{ properties + var $parser; var $fp; var $folding = true; + var $mode; + + // }}} + // {{{ constructor() - function XML_Parser($charset = 'UTF-8') { + function XML_Parser($charset = 'UTF-8', $mode = "event") { $this->PEAR(); $xp = @xml_parser_create($charset); if (is_resource($xp)) { $this->parser = $xp; + $this->setMode($mode); xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, $this->folding); - xml_set_object($xp, $this); - if (method_exists($this, "startHandler") || - method_exists($this, "endHandler")) { - xml_set_element_handler($xp, "startHandler", "endHandler"); - } - if (method_exists($this, "cdataHandler")) { - xml_set_character_data_handler($xp, "cdataHandler"); - } - if (method_exists($this, "defaultHandler")) { - xml_set_default_handler($xp, "defaultHandler"); - } - if (method_exists($this, "piHandler")) { - xml_set_processing_instruction_handler($xp, "piHandler"); - } - if (method_exists($this, "unparsedHandler")) { - xml_set_unparsed_entity_decl_handler($xp, "unparsedHandler"); - } - if (method_exists($this, "notationHandler")) { - xml_set_notation_decl_handler($xp, "notationHandler"); - } - if (method_exists($this, "entityrefHandler")) { - xml_set_external_entity_ref_handler($xp, "entityrefHandler"); - } } } + // }}} + + // {{{ setMode() + + function setMode($mode) { + $this->mode = $mode; + $xp = $this->parser; + xml_set_object($xp, $this); + switch ($mode) { + case "func": + xml_set_element_handler($xp, "funcStartHandler", "funcEndHandler"); + break; + case "event": + if (method_exists($this, "startHandler") || + method_exists($this, "endHandler")) { + xml_set_element_handler($xp, "startHandler", "endHandler"); + } + } + if (method_exists($this, "cdataHandler")) { + xml_set_character_data_handler($xp, "cdataHandler"); + } else { + xml_set_character_data_handler($xp, ""); + } + if (method_exists($this, "defaultHandler")) { + xml_set_default_handler($xp, "defaultHandler"); + } else { + xml_set_default_handler($xp, ""); + } + if (method_exists($this, "piHandler")) { + xml_set_processing_instruction_handler($xp, "piHandler"); + } else { + xml_set_processing_instruction_handler($xp, ""); + } + if (method_exists($this, "unparsedHandler")) { + xml_set_unparsed_entity_decl_handler($xp, "unparsedHandler"); + } else { + xml_set_unparsed_entity_decl_handler($xp, ""); + } + if (method_exists($this, "notationHandler")) { + xml_set_notation_decl_handler($xp, "notationHandler"); + } else { + xml_set_notation_decl_handler($xp, ""); + } + if (method_exists($this, "entityrefHandler")) { + xml_set_external_entity_ref_handler($xp, "entityrefHandler"); + } else { + xml_set_external_entity_ref_handler($xp, ""); + } + } + + // }}} + // {{{ setInputFile() + function setInputFile($file) { $fp = @fopen($file, "r"); if (is_resource($fp)) { @@ -59,6 +122,9 @@ return new XML_Parser_Error($php_errormsg); } + // }}} + // {{{ setInput() + function setInput($fp) { if (is_resource($fp)) { $this->fp = $fp; @@ -67,6 +133,9 @@ return new XML_Parser_Error("not a file resource"); } + // }}} + // {{{ parse() + function parse() { if (!is_resource($this->fp)) { return new XML_Parser_Error("no input"); @@ -83,6 +152,9 @@ return true; } + // }}} + // {{{ parseString() + function parseString($data, $eof = false) { if (!is_resource($this->parser)) { return new XML_Parser_Error("no parser"); @@ -95,15 +167,42 @@ return true; } + // }}} + // {{{ funcStartHandler() + + function funcStartHandler($xp, $elem, $attribs) { + if (method_exists($this, $elem)) { + call_user_method($elem, $this, $xp, $elem, &$attribs); + } + } + + // }}} + // {{{ funcEndHandler() + + function funcEndHandler($xp, $elem) { + $func = $elem . '_'; + if (method_exists($this, $func)) { + call_user_method($func, $this, $xp, $elem); + } + } + + // }}} } class XML_Parser_Error extends PEAR_Error { + // {{{ properties + var $error_message_prefix = 'XML_Parser: '; + + // }}} + // {{{ constructor() + function XML_Parser_Error($msgorparser = 'unknown error', $code = 0, $mode = PEAR_ERROR_RETURN, $level = E_USER_NOTICE) { if (is_resource($msgorparser)) { + $code = xml_get_error_code($msgorparser); $msgorparser = sprintf("%s at XML input line %d", xml_error_string(xml_get_error_code($msgorparser)), @@ -111,6 +210,8 @@ } $this->PEAR_Error($msgorparser, $code, $mode, $level); } + + // }}} } ?> Index: php4/pear/DB/tests/odbc/001.phpt +++ php4/pear/DB/tests/odbc/001.phpt --TEST-- ODBC DB::connect --SKIPIF-- <?php include("skipif.inc"); ?> --FILE-- <?php require_once "DB.php"; switch (ODBC_TYPE) { case "solid": $dsn = "tcp+localhost+1313"; break; default: $dsn = "localhost/test"; break; } $dbh = DB::connect("odbc://test:test@$dsn"); if (is_object($dbh)) { print "\$dbh is an object\n"; } if (is_resource($dbh->connection)) { print "\$dbh is connected\n"; } ?> --EXPECT-- $dbh is an object $dbh is connected Index: php4/pear/DB/tests/odbc/skipif.inc +++ php4/pear/DB/tests/odbc/skipif.inc <?php // This script prints "skip" unless: // * the odbc extension is built-in or loadable, AND // * there is a database called "test" accessible // with no username/password, AND // * we have create/drop privileges on the entire "test" // database die("skip\n"); if (!extension_loaded("odbc")) { $dlext = (substr(PHP_OS, 0, 3) == "WIN") ? ".dll" : ".so"; @dl("odbc$dlext"); } if (!extension_loaded("odbc")) { die("skip\n"); } switch (ODBC_TYPE) { case "solid": $dsn = "tcp localhost 1313"; $user = $pass = "test"; break; default: die("skip\n"); break; } $conn = @odbc_connect($dsn, $user, $pass); if (!is_resource($conn)) { die("skip\n"); } ?> Index: php4/pear/XML/tests/001.phpt +++ php4/pear/XML/tests/001.phpt --TEST-- XML Parser: parse simple string --FILE-- <?php // // Test for: XML/Parser.php // Parts tested: - parser creation // - some handlers // - parse simple string // require_once "XML/Parser.php"; class __TestParser1 extends XML_Parser { function __TestParser1() { $this->XML_Parser(); } function startHandler($xp, $element, $attribs) { print "<$element"; reset($attribs); while (list($key, $val) = each($attribs)) { $enc = htmlentities($val); print " $key=\"$enc\""; } print ">"; } function endHandler($xp, $element) { print "</$element>\n"; } function cdataHandler($xp, $cdata) { print "<![CDATA[$cdata]]>"; } function defaultHandler($xp, $cdata) { } } error_reporting(1023); print "new __TestParser1 "; var_dump(get_class($o = new __TestParser1())); print "parseString "; var_dump($o->parseString("<?xml version='1.0' ?><root>foo</root>", 1)); ?> --EXPECT-- new __TestParser1 string(13) "__testparser1" parseString <ROOT><![CDATA[foo]]></ROOT> bool(true) Index: php4/pear/XML/tests/002.phpt +++ php4/pear/XML/tests/002.phpt --TEST-- XML Parser: parse from file --FILE-- <?php // -*- C++ -*- // // Test for: XML/Parser.php // Parts tested: - parser creation // - some handlers // - parse from file // require_once "XML/Parser.php"; class __TestParser2 extends XML_Parser { function __TestParser2() { $this->XML_Parser(); } function startHandler($xp, $element, $attribs) { print "<$element"; reset($attribs); while (list($key, $val) = each($attribs)) { $enc = htmlentities($val); print " $key=\"$enc\""; } print ">"; } function endHandler($xp, $element) { print "</$element>\n"; } function cdataHandler($xp, $cdata) { print "<![CDATA[$cdata]]>"; } function defaultHandler($xp, $cdata) { } } print "new __TestParser2 "; var_dump(get_class($o = new __TestParser2())); print "setInputFile "; var_dump($o->setInputFile("parser2.i")); print "parse "; var_dump($o->parse()); ?> --EXPECT-- new __TestParser2 string(13) "__testparser2" setInputFile resource(2) of type 2 parse <ROOT><![CDATA[foo]]></ROOT> bool(true) Index: php4/pear/XML/tests/003.phpt +++ php4/pear/XML/tests/003.phpt --TEST-- XML Parser: parse from file resource --FILE-- <?php // -*- C++ -*- // // Test for: XML/Parser.php // Parts tested: - parser creation // - some handlers // - parse from file resource // require_once "XML/Parser.php"; class __TestParser3 extends XML_Parser { function __TestParser3() { $this->XML_Parser(); } function startHandler($xp, $element, $attribs) { print "<$element"; reset($attribs); while (list($key, $val) = each($attribs)) { $enc = htmlentities($val); print " $key=\"$enc\""; } print ">"; } function endHandler($xp, $element) { print "</$element>\n"; } function cdataHandler($xp, $cdata) { print "<![CDATA[$cdata]]>"; } function defaultHandler($xp, $cdata) { } } print "new __TestParser3 "; var_dump(get_class($o = new __TestParser3())); print "fopen "; var_dump($fp = fopen("test.xml", "r")); print "setInput "; var_dump($o->setInput($fp)); print "parse "; var_dump($o->parse()); ?> --EXPECT-- new __TestParser3 string(13) "__testparser3" fopen resource(2) of type 2 setInput bool(true) parse <ROOT><![CDATA[foo]]></ROOT> bool(true) Index: php4/pear/XML/tests/004.phpt +++ php4/pear/XML/tests/004.phpt --TEST-- XML Parser: error class --FILE-- <?php // -*- C++ -*- // // Test for: XML/Parser.php // Parts tested: - parser error class // require_once "XML/Parser.php"; print "new XML_Parser "; var_dump(get_class($p = new XML_Parser())); $e = $p->parseString("<?xml version='1.0' ?><foo></bar>", true); if (PEAR::isError($e)) { printf("error message: %s\n", $e->getMessage()); } else { print "no error\n"; } ?> --EXPECT-- new XML_Parser string(10) "xml_parser" error message: XML_Parser: mismatched tag at XML input line 1 Index: php4/pear/XML/tests/005.phpt +++ php4/pear/XML/tests/005.phpt --TEST-- XML Parser: mixing character encodings --FILE-- <?php // -*- C++ -*- // // Test for: XML/Parser.php // Parts tested: - mixing character encodings // // This is what we test: // 1 UTF-8 -> ISO-8859-1 // 2 UTF-8 -> US-ASCII // 3 ISO-8859-1 -> UTF-8 // 4 ISO-8859-1 -> US-ASCII // 5 US-ASCII -> UTF-8 // 6 US-ASCII -> ISO-8859-1 // require_once "XML/Parser.php"; $xml = "<?xml version='1.0' ?>"; $input = array( "UTF-8" => "<a>abcæøå</a>", "ISO-8859-1" => "<a>abcæøå</a>", "US-ASCII" => "<a>abcaoa</a>" ); $encodings = array_keys($input); for ($i = 0; $i < sizeof($encodings); $i++) { for ($j = 0; $j < sizeof($encodings); $j++) { if ($i == $j) { continue; } print "Testing $encodings[$i] -> $encodings[$j]: "; $p = new __TestEncodings1("UTF-8", "ISO-8859-1"); $snippet = $input[$encodings[$i]]; $e = $p->test($input[$encodings[$i]]); if (PEAR::isError($e)) { printf("OOPS: %s\n", $e->getMessage()); } else { var_dump($e); } } } class __TestEncodings1 extends XML_Parser { var $output = ''; function __TestEncodings1($to, $from) { $this->XML_Parser(array('input_encoding' => $from, 'output_encoding' => $to, 'case_folding' => false)); } function startHandler($xp, $elem, $attribs) { $this->output .= "<$elem>"; } function endHandler($xp, $elem) { $this->output .= "</$elem>"; } function cdataHandler($xp, $data) { $this->output .= $data; } function test($data) { $this->output = ''; $this->parseString($data, true); return $this->output; } } ?> --EXPECT-- Index: php4/pear/XML/tests/test.xml +++ php4/pear/XML/tests/test.xml <?xml version='1.0' ?> <root>foo</root>
« previous php.cvs (#2965) next »