cvs: php4 /pear/DB storage.php
| From: | Stig Bakken | Date: | Thu, 24 May 2001 11:55:38 +0000 |
| Subject: | cvs: php4 /pear/DB storage.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-192@lists.php.net to get a copy of this message | ||
ssb Thu May 24 04:55:38 2001 EDT
Modified files:
/php4/pear/DB storage.php
Log:
whitespace
Index: php4/pear/DB/storage.php diff -u php4/pear/DB/storage.php:1.16 php4/pear/DB/storage.php:1.17 --- php4/pear/DB/storage.php:1.16 Wed May 23 05:38:20 2001 +++ php4/pear/DB/storage.php Thu May 24 04:55:38 2001 @@ -45,16 +45,16 @@ var $_dbh = null; /** an assoc with the names of database fields stored as properties - in this object */ + in this object */ var $_properties = array(); /** an assoc with the names of the properties in this object that - have been changed since they were fetched from the database */ + have been changed since they were fetched from the database */ var $_changes = array(); /** flag that decides if data in this object can be changed. - objects that don't have their table's key column in their - property lists will be flagged as read-only. */ + objects that don't have their table's key column in their + property lists will be flagged as read-only. */ var $_readonly = false; /** function or method that implements a validator for fields that @@ -76,10 +76,10 @@ function DB_storage($table, $keycolumn, &$dbh) { $this->PEAR('DB_Error'); - $this->_table = $table; - $this->_keycolumn = $keycolumn; - $this->_dbh = $dbh; - $this->_readonly = false; + $this->_table = $table; + $this->_keycolumn = $keycolumn; + $this->_dbh = $dbh; + $this->_readonly = false; } /** @@ -134,18 +134,18 @@ */ function setup($keyval) { - if (is_int($keyval)) { - $qval = "$keyval"; - } else { - $qval = "'" . $this->_dbh->quoteString($keyval) . "'"; - } + if (is_int($keyval)) { + $qval = "$keyval"; + } else { + $qval = "'" . $this->_dbh->quoteString($keyval) . "'"; + } $whereclause = $this->_makeWhere($keyval); $query = 'SELECT * FROM ' . $this->_table . ' WHERE ' . $whereclause; - $sth = $this->_dbh->query($query); - if (DB::isError($sth)) { - return $sth; - } - $row = $sth->fetchRow(DB_FETCHMODE_ASSOC); + $sth = $this->_dbh->query($query); + if (DB::isError($sth)) { + return $sth; + } + $row = $sth->fetchRow(DB_FETCHMODE_ASSOC); if (DB::isError($row)) { return $row; } @@ -156,7 +156,7 @@ foreach ($row as $key => $value) { $this->_properties[$key] = true; $this->$key = $value; - } + } return DB_OK; } @@ -180,16 +180,16 @@ } } - $sth = $this->_dbh->query("INSERT INTO $this->_table (" . + $sth = $this->_dbh->query("INSERT INTO $this->_table (" . implode(",", $primarykey) . ") VALUES(" . implode(",", $pkvals) . ")"); - if (DB::isError($sth)) { - return $sth; - } + if (DB::isError($sth)) { + return $sth; + } if (sizeof($newpk) == 1) { $newpk = $newpk[0]; } - $this->setup($newpk); + $this->setup($newpk); } /** @@ -198,25 +198,25 @@ */ function toString() { - $info = get_class(&$this); - $info .= " (table="; - $info .= $this->_table; - $info .= ", keycolumn="; + $info = get_class(&$this); + $info .= " (table="; + $info .= $this->_table; + $info .= ", keycolumn="; if (is_array($this->_keycolumn)) { $info .= "(" . implode(",", $this->_keycolumn) . ")"; } else { $info .= $this->_keycolumn; + } + $info .= ", dbh="; + if (is_object($this->_dbh)) { + $info .= $this->_dbh->toString(); + } else { + $info .= "null"; } - $info .= ", dbh="; - if (is_object($this->_dbh)) { - $info .= $this->_dbh->toString(); - } else { - $info .= "null"; - } - $info .= ")"; - if (sizeof($this->_properties)) { + $info .= ")"; + if (sizeof($this->_properties)) { $info .= " [loaded, key="; - $keyname = $this->_keycolumn; + $keyname = $this->_keycolumn; if (is_array($keyname)) { $info .= "("; for ($i = 0; $i < sizeof($keyname); $i++) { @@ -229,12 +229,12 @@ } else { $info .= $this->$keyname; } - $info .= "]"; - } - if (sizeof($this->_changes)) { - $info .= " [modified]"; - } - return $info; + $info .= "]"; + } + if (sizeof($this->_changes)) { + $info .= " [modified]"; + } + return $info; } /** @@ -242,12 +242,12 @@ */ function dump() { - reset($this->_properties); - while (list($prop, $foo) = each($this->_properties)) { - print "$prop = "; - print htmlentities($this->$prop); - print "<BR>\n"; - } + reset($this->_properties); + while (list($prop, $foo) = each($this->_properties)) { + print "$prop = "; + print htmlentities($this->$prop); + print "<BR>\n"; + } } /** @@ -258,14 +258,14 @@ */ function &create($table, &$data) { - $classname = get_class(&$this); - $obj = new $classname($table); - reset($data); - while (list($name, $value) = each($data)) { - $obj->_properties[$name] = true; - $obj->$name = &$value; - } - return $obj; + $classname = get_class(&$this); + $obj = new $classname($table); + reset($data); + while (list($name, $value) = each($data)) { + $obj->_properties[$name] = true; + $obj->$name = &$value; + } + return $obj; } /** @@ -287,33 +287,33 @@ /* function loadFromQuery($query, $params = null) { - if (sizeof($this->_properties)) { - if (sizeof($this->_changes)) { - $this->store(); - $this->_changes = array(); - } - $this->_properties = array(); - } - $rowdata = $this->_dbh->getRow($query, DB_FETCHMODE_ASSOC, $params); - if (DB::isError($rowdata)) { - return $rowdata; - } - reset($rowdata); - $found_keycolumn = false; - while (list($key, $value) = each($rowdata)) { - if ($key == $this->_keycolumn) { - $found_keycolumn = true; - } - $this->_properties[$key] = true; - $this->$key = &$value; - unset($value); // have to unset, or all properties will - // refer to the same value - } - if (!$found_keycolumn) { - $this->_readonly = true; - return DB_WARNING_READ_ONLY; - } - return DB_OK; + if (sizeof($this->_properties)) { + if (sizeof($this->_changes)) { + $this->store(); + $this->_changes = array(); + } + $this->_properties = array(); + } + $rowdata = $this->_dbh->getRow($query, DB_FETCHMODE_ASSOC, $params); + if (DB::isError($rowdata)) { + return $rowdata; + } + reset($rowdata); + $found_keycolumn = false; + while (list($key, $value) = each($rowdata)) { + if ($key == $this->_keycolumn) { + $found_keycolumn = true; + } + $this->_properties[$key] = true; + $this->$key = &$value; + unset($value); // have to unset, or all properties will + // refer to the same value + } + if (!$found_keycolumn) { + $this->_readonly = true; + return DB_WARNING_READ_ONLY; + } + return DB_OK; } */ @@ -322,13 +322,13 @@ */ function set($property, &$newvalue) { - // only change if $property is known and object is not - // read-only + // only change if $property is known and object is not + // read-only if ($this->_readonly) { return $this->raiseError(null, DB_WARNING_READ_ONLY, null, null, null, null, true); } - if (empty($this->_readonly) && isset($this->_properties[$property])) { + if (empty($this->_readonly) && isset($this->_properties[$property])) { if (empty($this->_validator)) { $valid = true; } else { @@ -344,9 +344,9 @@ null, "invalid field: $property", null, true); } - return true; - } - return $this->raiseError(null, DB_ERROR_NOSUCHFIELD, null, + return true; + } + return $this->raiseError(null, DB_ERROR_NOSUCHFIELD, null, null, "unknown field: $property", null, true); } @@ -361,11 +361,11 @@ */ function &get($property) { - // only return if $property is known - if (isset($this->_properties[$property])) { - return $this->$property; - } - return null; + // only return if $property is known + if (isset($this->_properties[$property])) { + return $this->$property; + } + return null; } /** @@ -374,12 +374,12 @@ */ function _DB_storage() { - if (!empty($this->_discard) && sizeof($this->_changes)) { - $this->store(); - } - $this->_properties = array(); - $this->_changes = array(); - $this->_table = null; + if (!empty($this->_discard) && sizeof($this->_changes)) { + $this->store(); + } + $this->_properties = array(); + $this->_changes = array(); + $this->_table = null; } /** @@ -389,22 +389,22 @@ */ function store() { - while (list($name, $changed) = each($this->_changes)) { - $params[] = &$this->$name; - $vars[] = $name . ' = ?'; - } - if ($vars) { - $query = 'UPDATE ' . $this->_table . ' SET ' . - implode(', ', $vars) . ' WHERE ' . + while (list($name, $changed) = each($this->_changes)) { + $params[] = &$this->$name; + $vars[] = $name . ' = ?'; + } + if ($vars) { + $query = 'UPDATE ' . $this->_table . ' SET ' . + implode(', ', $vars) . ' WHERE ' . $this->_makeWhere(); - $stmt = $this->_dbh->query($query); - $res = $this->_dbh->execute($stmt, &$params); - if (DB::isError($res)) { - return $res; - } - $this->_changes = array(); - } - return DB_OK; + $stmt = $this->_dbh->query($query); + $res = $this->_dbh->execute($stmt, &$params); + if (DB::isError($res)) { + return $res; + } + $this->_changes = array(); + } + return DB_OK; } /**
Index: php4/pear/DB/storage.php diff -u php4/pear/DB/storage.php:1.16 php4/pear/DB/storage.php:1.17 --- php4/pear/DB/storage.php:1.16 Wed May 23 05:38:20 2001 +++ php4/pear/DB/storage.php Thu May 24 04:55:38 2001 @@ -45,16 +45,16 @@ var $_dbh = null; /** an assoc with the names of database fields stored as properties - in this object */ + in this object */ var $_properties = array(); /** an assoc with the names of the properties in this object that - have been changed since they were fetched from the database */ + have been changed since they were fetched from the database */ var $_changes = array(); /** flag that decides if data in this object can be changed. - objects that don't have their table's key column in their - property lists will be flagged as read-only. */ + objects that don't have their table's key column in their + property lists will be flagged as read-only. */ var $_readonly = false; /** function or method that implements a validator for fields that @@ -76,10 +76,10 @@ function DB_storage($table, $keycolumn, &$dbh) { $this->PEAR('DB_Error'); - $this->_table = $table; - $this->_keycolumn = $keycolumn; - $this->_dbh = $dbh; - $this->_readonly = false; + $this->_table = $table; + $this->_keycolumn = $keycolumn; + $this->_dbh = $dbh; + $this->_readonly = false; } /** @@ -134,18 +134,18 @@ */ function setup($keyval) { - if (is_int($keyval)) { - $qval = "$keyval"; - } else { - $qval = "'" . $this->_dbh->quoteString($keyval) . "'"; - } + if (is_int($keyval)) { + $qval = "$keyval"; + } else { + $qval = "'" . $this->_dbh->quoteString($keyval) . "'"; + } $whereclause = $this->_makeWhere($keyval); $query = 'SELECT * FROM ' . $this->_table . ' WHERE ' . $whereclause; - $sth = $this->_dbh->query($query); - if (DB::isError($sth)) { - return $sth; - } - $row = $sth->fetchRow(DB_FETCHMODE_ASSOC); + $sth = $this->_dbh->query($query); + if (DB::isError($sth)) { + return $sth; + } + $row = $sth->fetchRow(DB_FETCHMODE_ASSOC); if (DB::isError($row)) { return $row; } @@ -156,7 +156,7 @@ foreach ($row as $key => $value) { $this->_properties[$key] = true; $this->$key = $value; - } + } return DB_OK; } @@ -180,16 +180,16 @@ } } - $sth = $this->_dbh->query("INSERT INTO $this->_table (" . + $sth = $this->_dbh->query("INSERT INTO $this->_table (" . implode(",", $primarykey) . ") VALUES(" . implode(",", $pkvals) . ")"); - if (DB::isError($sth)) { - return $sth; - } + if (DB::isError($sth)) { + return $sth; + } if (sizeof($newpk) == 1) { $newpk = $newpk[0]; } - $this->setup($newpk); + $this->setup($newpk); } /** @@ -198,25 +198,25 @@ */ function toString() { - $info = get_class(&$this); - $info .= " (table="; - $info .= $this->_table; - $info .= ", keycolumn="; + $info = get_class(&$this); + $info .= " (table="; + $info .= $this->_table; + $info .= ", keycolumn="; if (is_array($this->_keycolumn)) { $info .= "(" . implode(",", $this->_keycolumn) . ")"; } else { $info .= $this->_keycolumn; + } + $info .= ", dbh="; + if (is_object($this->_dbh)) { + $info .= $this->_dbh->toString(); + } else { + $info .= "null"; } - $info .= ", dbh="; - if (is_object($this->_dbh)) { - $info .= $this->_dbh->toString(); - } else { - $info .= "null"; - } - $info .= ")"; - if (sizeof($this->_properties)) { + $info .= ")"; + if (sizeof($this->_properties)) { $info .= " [loaded, key="; - $keyname = $this->_keycolumn; + $keyname = $this->_keycolumn; if (is_array($keyname)) { $info .= "("; for ($i = 0; $i < sizeof($keyname); $i++) { @@ -229,12 +229,12 @@ } else { $info .= $this->$keyname; } - $info .= "]"; - } - if (sizeof($this->_changes)) { - $info .= " [modified]"; - } - return $info; + $info .= "]"; + } + if (sizeof($this->_changes)) { + $info .= " [modified]"; + } + return $info; } /** @@ -242,12 +242,12 @@ */ function dump() { - reset($this->_properties); - while (list($prop, $foo) = each($this->_properties)) { - print "$prop = "; - print htmlentities($this->$prop); - print "<BR>\n"; - } + reset($this->_properties); + while (list($prop, $foo) = each($this->_properties)) { + print "$prop = "; + print htmlentities($this->$prop); + print "<BR>\n"; + } } /** @@ -258,14 +258,14 @@ */ function &create($table, &$data) { - $classname = get_class(&$this); - $obj = new $classname($table); - reset($data); - while (list($name, $value) = each($data)) { - $obj->_properties[$name] = true; - $obj->$name = &$value; - } - return $obj; + $classname = get_class(&$this); + $obj = new $classname($table); + reset($data); + while (list($name, $value) = each($data)) { + $obj->_properties[$name] = true; + $obj->$name = &$value; + } + return $obj; } /** @@ -287,33 +287,33 @@ /* function loadFromQuery($query, $params = null) { - if (sizeof($this->_properties)) { - if (sizeof($this->_changes)) { - $this->store(); - $this->_changes = array(); - } - $this->_properties = array(); - } - $rowdata = $this->_dbh->getRow($query, DB_FETCHMODE_ASSOC, $params); - if (DB::isError($rowdata)) { - return $rowdata; - } - reset($rowdata); - $found_keycolumn = false; - while (list($key, $value) = each($rowdata)) { - if ($key == $this->_keycolumn) { - $found_keycolumn = true; - } - $this->_properties[$key] = true; - $this->$key = &$value; - unset($value); // have to unset, or all properties will - // refer to the same value - } - if (!$found_keycolumn) { - $this->_readonly = true; - return DB_WARNING_READ_ONLY; - } - return DB_OK; + if (sizeof($this->_properties)) { + if (sizeof($this->_changes)) { + $this->store(); + $this->_changes = array(); + } + $this->_properties = array(); + } + $rowdata = $this->_dbh->getRow($query, DB_FETCHMODE_ASSOC, $params); + if (DB::isError($rowdata)) { + return $rowdata; + } + reset($rowdata); + $found_keycolumn = false; + while (list($key, $value) = each($rowdata)) { + if ($key == $this->_keycolumn) { + $found_keycolumn = true; + } + $this->_properties[$key] = true; + $this->$key = &$value; + unset($value); // have to unset, or all properties will + // refer to the same value + } + if (!$found_keycolumn) { + $this->_readonly = true; + return DB_WARNING_READ_ONLY; + } + return DB_OK; } */ @@ -322,13 +322,13 @@ */ function set($property, &$newvalue) { - // only change if $property is known and object is not - // read-only + // only change if $property is known and object is not + // read-only if ($this->_readonly) { return $this->raiseError(null, DB_WARNING_READ_ONLY, null, null, null, null, true); } - if (empty($this->_readonly) && isset($this->_properties[$property])) { + if (empty($this->_readonly) && isset($this->_properties[$property])) { if (empty($this->_validator)) { $valid = true; } else { @@ -344,9 +344,9 @@ null, "invalid field: $property", null, true); } - return true; - } - return $this->raiseError(null, DB_ERROR_NOSUCHFIELD, null, + return true; + } + return $this->raiseError(null, DB_ERROR_NOSUCHFIELD, null, null, "unknown field: $property", null, true); } @@ -361,11 +361,11 @@ */ function &get($property) { - // only return if $property is known - if (isset($this->_properties[$property])) { - return $this->$property; - } - return null; + // only return if $property is known + if (isset($this->_properties[$property])) { + return $this->$property; + } + return null; } /** @@ -374,12 +374,12 @@ */ function _DB_storage() { - if (!empty($this->_discard) && sizeof($this->_changes)) { - $this->store(); - } - $this->_properties = array(); - $this->_changes = array(); - $this->_table = null; + if (!empty($this->_discard) && sizeof($this->_changes)) { + $this->store(); + } + $this->_properties = array(); + $this->_changes = array(); + $this->_table = null; } /** @@ -389,22 +389,22 @@ */ function store() { - while (list($name, $changed) = each($this->_changes)) { - $params[] = &$this->$name; - $vars[] = $name . ' = ?'; - } - if ($vars) { - $query = 'UPDATE ' . $this->_table . ' SET ' . - implode(', ', $vars) . ' WHERE ' . + while (list($name, $changed) = each($this->_changes)) { + $params[] = &$this->$name; + $vars[] = $name . ' = ?'; + } + if ($vars) { + $query = 'UPDATE ' . $this->_table . ' SET ' . + implode(', ', $vars) . ' WHERE ' . $this->_makeWhere(); - $stmt = $this->_dbh->query($query); - $res = $this->_dbh->execute($stmt, &$params); - if (DB::isError($res)) { - return $res; - } - $this->_changes = array(); - } - return DB_OK; + $stmt = $this->_dbh->query($query); + $res = $this->_dbh->execute($stmt, &$params); + if (DB::isError($res)) { + return $res; + } + $this->_changes = array(); + } + return DB_OK; } /**