cvs: pear /MDB/MDB Common.php

From: Date: Mon, 03 Feb 2003 14:31:53 +0000
Subject: cvs: pear /MDB/MDB Common.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-8704@lists.php.net to get a copy of this message
lsmith Mon Feb 3 09:31:53 2003 EDT Modified files: /pear/MDB/MDB Common.php Log: - made the replace emulation more conformant with how replace works in mysql - fixed a bug in convertResultRow() when using the associative fetchmode Index: pear/MDB/MDB/Common.php diff -u pear/MDB/MDB/Common.php:1.88 pear/MDB/MDB/Common.php:1.89 --- pear/MDB/MDB/Common.php:1.88 Mon Jan 27 17:09:37 2003 +++ pear/MDB/MDB/Common.php Mon Feb 3 09:31:53 2003 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.88 2003/01/27 22:09:37 lsmith Exp $ +// $Id: Common.php,v 1.89 2003/02/03 14:31:53 lsmith Exp $ /** * @package MDB @@ -1520,17 +1520,15 @@ return($this->raiseError(MDB_ERROR_UNSUPPORTED, '', '', 'Replace: replace query is not supported')); } $count = count($fields); - for($keys = 0, $condition = $update = $insert = $values = '', reset($fields), $field = 0; + for($keys = 0, $condition = $insert = $values = '', reset($fields), $field = 0; $field < $count; next($fields), $field++) { $name = key($fields); if ($field > 0) { - $update .= ', '; $insert .= ', '; $values .= ', '; } - $update .= $name; $insert .= $name; if (isset($fields[$name]['Null']) && $fields[$name]['Null']) { $value = 'NULL'; @@ -1573,7 +1571,6 @@ $value = $fields[$name]['Value']; } } - $update .= '=' . $value; $values .= $value; if (isset($fields[$name]['Key']) && $fields[$name]['Key']) { if ($value == 'NULL') { @@ -1591,24 +1588,11 @@ if (!($in_transaction = $this->in_transaction) && MDB::isError($result = $this->autoCommit(FALSE))) { return($result); } - $affected_rows = $this->queryOne("SELECT COUNT(*) FROM $table$condition", "integer"); - if (!MDB::isError($affected_rows)) { - switch ($affected_rows) { - case 0: - $success = $this->query("INSERT INTO $table ($insert) VALUES ($values)"); - $affected_rows = 1; - break; - case 1: - $success = $this->query("UPDATE $table SET $update$condition"); - $affected_rows = $this->affected_rows * 2; - break; - default: - $success = $this->raiseError(MDB_ERROR_CANNOT_REPLACE, '', '', - 'replace keys are not unique'); - break; - } - } else { - $success = $affected_rows; + $success = $this->query("DELETE FROM $table$condition"); + if (!MDB::isError($success)) { + $affected_rows = $this->affected_rows; + $success = $this->query("INSERT INTO $table ($insert) VALUES ($values)"); + $affected_rows += $this->affected_rows; } if (!$in_transaction) { @@ -2676,30 +2660,28 @@ function convertResultRow($result, $row) { if (isset($this->result_types[$result])) { - $columns = $this->numCols($result); - if (MDB::isError($columns)) { - return($columns); - } - for($column = 0; $column < $columns; $column++) { - if (!isset($row[$column])) { + $current_column = 0; + foreach($row as $key => $column) { + if (!isset($column)) { continue; } - switch ($type = $this->result_types[$result][$column]) { + switch ($type = $this->result_types[$result][$current_column]) { case MDB_TYPE_TEXT: case MDB_TYPE_BLOB: case MDB_TYPE_CLOB: break; case MDB_TYPE_INTEGER: - $row[$column] = intval($row[$column]); + $row[$key] = intval($row[$key]); break; default: - $value = $this->convertResult($row[$column], $type); + $value = $this->convertResult($row[$key], $type); if (MDB::isError($value)) { - return($value); + return $value; } - $row[$column] = $value; + $row[$key] = $value; break; } + ++$current_column; } } return($row);

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