/** * Prepares the delete SQL query to be executed * @access protected */ function prepareSQL() { tNG_log::log('tNG_delete', 'prepareSQL', 'begin'); parent::prepareSQL(); // check if we have a valid primaryKey if (!$this->primaryKey) { $ret = new tNG_error('DEL_NO_PK_SET', array(), array()); } // check the primary key value if (!isset($this->primaryKeyColumn['value'])) { $ret = new tNG_error('DEL_NO_PK_VAL', array(), array()); } $ret = null; $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . KT_escapeFieldName($this->primaryKey) . ' = '; $sql .= KT_escapeForSql($this->primaryKeyColumn['value'], $this->primaryKeyColumn['type']); $this->setSQL($sql); tNG_log::log('tNG_delete', 'prepareSQL', 'end'); return $ret; }
/** * Prepares the update SQL query to be executed * @access protected */ function prepareSQL() { tNG_log::log('tNG_update', 'prepareSQL', 'begin'); parent::prepareSQL(); // check if we have a valid primaryKey if ($this->primaryKey == '') { return new tNG_error('UPD_NO_PK_SET', array(), array()); } // check the primary key value if (!isset($this->primaryKeyColumn['value'])) { return new tNG_error('UPD_NO_PK_SET', array(), array()); } // begin the SQL generator $sql = 'UPDATE ' . $this->table . ' SET '; $KT_sp = false; foreach ($this->columns as $colName => $colDetails) { $colType = $this->columns[$colName]['type']; $colValue = $this->columns[$colName]['value']; $colMethod = $this->columns[$colName]['method']; $sep = $KT_sp ? ', ' : ''; // set the separator ',' (first time will be none) if ($colType == 'FILE_TYPE' || $colMethod == 'CURRVAL') { $sql .= $sep . KT_escapeFieldName($colName) . '=' . KT_escapeFieldName($colName); } else { // if we handle a hidden field, we should not use it in the update SQL. // add the column to the SQL string $sql .= $sep . KT_escapeFieldName($colName) . '=' . KT_escapeForSql($colValue, $colType); } $KT_sp = true; } if (!$KT_sp) { // no column was actually added return new tNG_error('UPD_NO_FIELDS', array(), array()); } // add the where clause $sql .= ' WHERE ' . KT_escapeFieldName($this->primaryKey) . ' = '; $sql .= KT_escapeForSql($this->primaryKeyColumn['value'], $this->primaryKeyColumn['type']); $this->setSQL($sql); tNG_log::log('tNG_update', 'prepareSQL', 'end'); return null; }
/** * Adds a column to the transaction * Calls the parent addColumn method then sets the default value. * @param string $colName The column name * @param string $type The column type (NUMERYC_TYPE, STRING_TYPE, etc) * @param string $method The request method (GET, POST, FILE, COOKIE, SESSION) * @param string $reference The submitted variable name (if method=GET and reference=test, value=$_GET['test']) * @param string $defaultValue The default value for the current column * @access public */ function addColumn($colName, $type, $method, $reference, $defaultValue = '') { parent::addColumn($colName, $type, $method, $reference); $this->columns[$colName]['default'] = $defaultValue; }
/** * Adds a column to the transaction * Calls the parent addColumn method then sets the default value. * @param string $colName The column name * @param string $type The column type (NUMERYC_TYPE, STRING_TYPE, etc) * @param string $method The request method (GET, POST, FILE, COOKIE, SESSION) * @param string $reference The submitted variable name (if method=GET and reference=test, value=$_GET['test']) * @param string $defaultValue The default value for the current column * @access public */ function addColumn($colName, $type, $method, $reference, $defaultValue = '') { parent::addColumn($colName, $type, $method, $reference); if ($method == "VALUE") { $this->columns[$colName]['default'] = $reference; } else { $this->columns[$colName]['default'] = $defaultValue; } }
/** * Gets the error message * @return string transaction error message (formatted) * @access public */ function getErrorMsg() { $ret_warning = ''; if (isset($this->noSuccess) && $this->noSuccess != 0) { $ret_warning = KT_getResource('MULTIPLE_OPERATIONS_SUCCEDED', 'tNG', array($this->noSuccess)); } if (!$this->getError()) { return array($ret_warning, '', ''); } $this->compileError(); $ret = parent::getErrorMsg(); $ret[0] .= $ret_warning; return $ret; }