applied tbsky's so_sql patch:

1. remove a redundant line (var $non_db_cols = array();)
2. make read function process scalar value, as ur comment say.
3. make search function work on "NULL" values
This commit is contained in:
Ralf Becker 2003-11-03 16:19:48 +00:00
parent 0d40fed412
commit e5f6a0ae08

View File

@ -48,7 +48,6 @@ class so_sql
var $data; // holds the content of all db_cols var $data; // holds the content of all db_cols
var $debug = 0; var $debug = 0;
var $empty_on_write = 'NULL'; var $empty_on_write = 'NULL';
var $non_db_cols = array();
/*! /*!
@function so_sql @function so_sql
@ -217,6 +216,12 @@ class so_sql
*/ */
function read($keys) function read($keys)
{ {
if (!is_array($keys))
{
$pk = array_keys($this->db_key_cols);
if ($pk) $keys = array($pk[0] => $keys);
}
$this->init($keys); $this->init($keys);
$this->data2db(); $this->data2db();
@ -324,7 +329,7 @@ class so_sql
$keys = ''; $keys = '';
foreach($this->db_key_cols as $db_col => $col) foreach($this->db_key_cols as $db_col => $col)
{ {
$keys .= ($keys ? ',':'') . "$db_col='".addslashes($this->data[$col])."'"; $keys .= ($keys ? ' AND ':'') . "$db_col='".addslashes($this->data[$col])."'";
} }
$this->db->query($sql = "UPDATE $this->table_name SET $vals WHERE $keys",__LINE__,__FILE__); $this->db->query($sql = "UPDATE $this->table_name SET $vals WHERE $keys",__LINE__,__FILE__);
} }
@ -393,14 +398,20 @@ class so_sql
{ {
if (!is_array($criteria)) if (!is_array($criteria))
{ {
$query = ' WHERE '.$criteria; $query = $criteria ? ' WHERE '.$criteria : '';
} }
else else
{ {
$criteria = $this->data2db($criteria); $criteria = $this->data2db($criteria);
foreach($this->db_cols as $db_col => $col) foreach($this->db_cols as $db_col => $col)
{ //echo "testing col='$col', criteria[$col]='".$criteria[$col]."'<br>"; { //echo "testing col='$col', criteria[$col]='".$criteria[$col]."'<br>";
if (isset($criteria[$col]) && ($empty || $criteria[$col] != '')) if (array_key_exists($col,$criteria) && ($empty || $criteria[$col] != ''))
{
if ($criteria[$col] === NULL)
{
$query .= ($query ? " $op " : ' WHERE ') . "$db_col IS NULL";
}
else
{ {
$query .= ($query ? " $op " : ' WHERE ') . $db_col . $query .= ($query ? " $op " : ' WHERE ') . $db_col .
($wildcard || strstr($criteria[$col],'*') || strstr($criteria[$col],'?') ? ($wildcard || strstr($criteria[$col],'*') || strstr($criteria[$col],'?') ?
@ -409,6 +420,7 @@ class so_sql
} }
} }
} }
}
$this->db->query($sql = 'SELECT '.($only_keys ? implode(',',$this->db_key_cols) : '*'). $this->db->query($sql = 'SELECT '.($only_keys ? implode(',',$this->db_key_cols) : '*').
($extra_cols != '' ? ",$extra_cols" : '')." FROM $this->table_name $query" . ($extra_cols != '' ? ",$extra_cols" : '')." FROM $this->table_name $query" .
($order_by != '' ? " ORDER BY $order_by" : ''),__LINE__,__FILE__); ($order_by != '' ? " ORDER BY $order_by" : ''),__LINE__,__FILE__);