| 107 |
/** |
/** |
| 108 |
* Sets the SQL query string for later execution. |
* Sets the SQL query string for later execution. |
| 109 |
* |
* |
| 110 |
|
* @param string The SQL query |
| 111 |
|
*/ |
| 112 |
|
function setBareQuery ($sql) { |
| 113 |
|
$this->_sql = $sql; |
| 114 |
|
} |
| 115 |
|
/** |
| 116 |
|
* Sets the SQL query string for later execution. |
| 117 |
|
* |
| 118 |
* This function replaces a string identifier <var>$prefix</var> with the |
* This function replaces a string identifier <var>$prefix</var> with the |
| 119 |
* string held is the <var>_table_prefix</var> class variable. |
* string held is the <var>_table_prefix</var> class variable. |
| 120 |
* |
* |
| 122 |
* @param string The common table prefix |
* @param string The common table prefix |
| 123 |
*/ |
*/ |
| 124 |
function setQuery( $sql, $prefix='#__' ) { |
function setQuery( $sql, $prefix='#__' ) { |
| 125 |
$this->_sql = $this->replacePrefix($sql, $prefix); |
$this->setBareQuery ($this->replacePrefix($sql, $prefix)); |
| 126 |
// This is maintenance code for catching particular SQL statements |
// This is maintenance code for catching particular SQL statements |
| 127 |
// if (strpos($this->_sql,'SELECT menutype') === 0) debug_print_backtrace(); |
// if (strpos($this->_sql,'SELECT menutype') === 0) debug_print_backtrace(); |
| 128 |
} |
} |
| 405 |
*/ |
*/ |
| 406 |
function insertObject( $table, &$object, $keyName = NULL, $verbose=false ) { |
function insertObject( $table, &$object, $keyName = NULL, $verbose=false ) { |
| 407 |
$fmtsql = "INSERT INTO $table ( %s ) VALUES ( %s ) "; |
$fmtsql = "INSERT INTO $table ( %s ) VALUES ( %s ) "; |
| 408 |
|
$fmtsql = $this->replacePrefix($fmtsql); |
| 409 |
$fields = array(); |
$fields = array(); |
| 410 |
foreach (get_object_vars( $object ) as $k => $v) { |
foreach (get_object_vars( $object ) as $k => $v) { |
| 411 |
if (is_array($v) OR is_object($v) OR $v === NULL OR $k[0] == '_') continue; |
if (is_array($v) OR is_object($v) OR $v === NULL OR $k[0] == '_') continue; |
| 413 |
$values[] = "'" . $this->getEscaped( $v ) . "'"; |
$values[] = "'" . $this->getEscaped( $v ) . "'"; |
| 414 |
} |
} |
| 415 |
if (!isset($fields)) die ('class database method insertObject - no fields'); |
if (!isset($fields)) die ('class database method insertObject - no fields'); |
| 416 |
$this->setQuery( sprintf( $fmtsql, implode( ",", $fields ), implode( ",", $values ) ) ); |
$this->setBareQuery( sprintf( $fmtsql, implode( ",", $fields ), implode( ",", $values ) ) ); |
| 417 |
($verbose) && print "$sql<br />\n"; |
($verbose) && print "$sql<br />\n"; |
| 418 |
if (!$this->query()) return false; |
if (!$this->query()) return false; |
| 419 |
$id = mysql_insert_id(); |
$id = mysql_insert_id(); |
| 431 |
*/ |
*/ |
| 432 |
function updateObject( $table, &$object, $keyName, $updateNulls=true ) { |
function updateObject( $table, &$object, $keyName, $updateNulls=true ) { |
| 433 |
$fmtsql = "UPDATE $table SET %s WHERE %s"; |
$fmtsql = "UPDATE $table SET %s WHERE %s"; |
| 434 |
|
$fmtsql = $this->replacePrefix($fmtsql); |
| 435 |
$tmp = array(); |
$tmp = array(); |
| 436 |
foreach (get_object_vars( $object ) as $k => $v) { |
foreach (get_object_vars( $object ) as $k => $v) { |
| 437 |
if (is_array($v) OR is_object($v) OR $k[0] == '_' OR ($v === null AND !$updateNulls)) continue; |
if (is_array($v) OR is_object($v) OR $k[0] == '_' OR ($v === null AND !$updateNulls)) continue; |
| 444 |
} |
} |
| 445 |
if (!isset($tmp)) return true; |
if (!isset($tmp)) return true; |
| 446 |
if (!isset($where)) die ('database class updateObject method - no key value'); |
if (!isset($where)) die ('database class updateObject method - no key value'); |
| 447 |
$this->setQuery( sprintf( $fmtsql, implode( ",", $tmp ) , $where ) ); |
$this->setBareQuery( sprintf( $fmtsql, implode( ",", $tmp ) , $where ) ); |
| 448 |
return $this->query(); |
return $this->query(); |
| 449 |
} |
} |
| 450 |
|
|