Exemplo n.º 1
0
 /**
  * Prepares the custom SQL query to be executed
  * @access protected
  */
 function prepareSQL()
 {
     tNG_log::log('tNG_custom', 'prepareSQL', 'begin');
     parent::prepareSQL();
     $sql = KT_DynamicData($this->sql, $this, "SQL");
     $this->setSQL($sql);
     tNG_log::log('tNG_custom', 'prepareSQL', 'end');
     return null;
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * Prepares the insert SQL query to be executed
  * @access protected
  */
 function prepareSQL()
 {
     tNG_log::log('tNG_insert', 'prepareSQL', 'begin');
     parent::prepareSQL();
     // check the columns number
     $sql = 'INSERT INTO ' . $this->table;
     $tmColStr = $tmValStr = '';
     $KT_sp = false;
     //generate the column and the value strings
     foreach ($this->columns as $colName => $colDetail) {
         $colType = $colDetail['type'];
         $colValue = $colDetail['value'];
         $colMethod = $colDetail['method'];
         if ($colMethod != 'HIDDEN') {
             // if we handle a hidden field, we should not use it in the update SQL.
             $sep = $KT_sp ? ', ' : '';
             // set the separator ',' (first time will be none)
             $KT_sp = true;
             //build the nameList and valueList
             $tmColStr = $tmColStr . $sep . KT_escapeFieldName($colName);
             if ($colType == "FILE_TYPE") {
                 // if we handle a file upload, the file name will be set afterwards.
                 $tmValStr = $tmValStr . $sep . "''";
             } else {
                 $tmValStr = $tmValStr . $sep . KT_escapeForSql($colValue, $colType);
             }
         }
     }
     if (!$KT_sp) {
         // no column was actually added
         die('tNG_insert.prepareSQL:<br />Please specify some fields to insert.');
     }
     // build the final SQL
     $sql .= ' (' . $tmColStr . ') values (' . $tmValStr . ')';
     $this->setSQL($sql);
     tNG_log::log('tNG_insert', 'prepareSQL', 'end');
     return null;
 }