/**
  * Delete an existing row
  *
  * @author Fernando Ontiveros Lira <*****@*****.**>
  * @access public
  * @return boolean
  */
 public function delete()
 {
     $stQry = "delete from `" . $this->table_name . "` ";
     $stWhere = '';
     $remainKeys = array();
     if (defined('DB_ADAPTER')) {
         $DBEngine = DB_ADAPTER;
     } else {
         $DBEngine = 'mysql';
     }
     foreach ($this->table_keys as $k => $v) {
         $remainKeys[$v] = false;
     }
     if (is_array($this->Fields)) {
         foreach ($this->Fields as $field => $val) {
             $iskey = false;
             $iskey = in_array($field, $this->table_keys);
             if ($iskey == true) {
                 if ($stWhere == "") {
                     $stWhere .= $field . "='" . G::sqlEscape($val, isset($this->_dbc->type) ? $this->_dbc->type : $DBEngine) . "'";
                 } else {
                     $stWhere .= " AND " . $field . "='" . G::sqlEscape($val, isset($this->_dbc->type) ? $this->_dbc->type : $DBEngine) . "'";
                 }
                 $remainKeys[$field] = true;
             }
         }
     }
     foreach ($remainKeys as $field => $bool) {
         if ($bool == false) {
             if ($stWhere != "") {
                 $stWhere .= " AND ";
             }
             $stWhere .= $field . "= ''";
             $remainKeys[$field] = true;
         }
     }
     $stQry = trim($stQry);
     $stWhere = trim($stWhere);
     if ($stWhere == '') {
         $dberror = PEAR::raiseError(null, G_ERROR_WARNING_MESSAGE, null, 'null', "You tried to call delete method without WHERE clause, if you want to delete all records use dbsession", 'G_Error', true);
         DBconnection::logError($dberror, $this->errorLevel);
         return $dberror;
     }
     $stQry .= " WHERE " . $stWhere;
     $result = $this->_dbses->execute($stQry, $this->debug, $this->errorLevel);
     $this->is_new = false;
     return $result;
 }
 /**
  * Function Read
  *
  * @author David S. Callizaya S. <*****@*****.**>
  * @access public
  * @return string
  */
 function Read()
 {
     if ($this->result === null) {
         $dberror = PEAR::raiseError(null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null', "You tried to call to a DBRecordset with an invalid result recordset.", 'G_Error', true);
         DBconnection::logError($dberror);
     }
     $res = $this->result->fetchRow(DB_FETCHMODE_ASSOC);
     //for Pgsql databases,
     //if ( PEAR_DATABASE == "pgsql" && is_array ( $res ) ) { $res = array_change_key_case( $res, CASE_UPPER);  }
     /* Comment Code: This block is not required now because
      *  of the the use of the G::sqlEscape() instead of addslashes
      *  funcion over each  field in DBTable.
      * @author David Callizaya
      */
     /*if (is_array ($res) )
       foreach ($res as $key => $val)
       $res[$key] = stripslashes ($val);  remove the slashes*/
     return $res;
 }
 /**
  * Function Execute, to execute a query and send back the recordset.
  *
  * @access public
  * @param eter string strQuery
  * @param eter string debug
  * @param eter string error
  * @return string
  */
 function Execute($strQuery = '', $debug = false, $errorLevel = null)
 {
     //BUG::traceRoute();
     if ($this->dbc == null) {
         $dberror = PEAR::raiseError(null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null', 'You have tried to call a DBSession function without create an instance of DBConnection', 'G_Error', true);
         DBconnection::logError($dberror, $errorLevel);
         return $dberror;
     }
     if ($errorLevel === null) {
         $errorLevel = $this->dbc->errorLevel;
     }
     $this->Free(true);
     if ($debug) {
         print $strQuery . "<br>\n";
     }
     $this->result = $this->dbc->db->query($strQuery);
     if (DB::isError($this->result)) {
         $this->dbc->logError($this->result, $errorLevel);
         return $this->result;
     }
     $dset = new DBRecordSet($this->result);
     return $dset;
 }
 /**
  * Gets last autoincrement value inserted
  *
  * @author Fernando Ontiveros Lira <*****@*****.**>
  * @access public
  * @return void
  */
 function GetLastID()
 {
     if (PEAR_DATABASE == "mysql") {
         return mysql_insert_id();
     } else {
         $dberror = PEAR::raiseError(null, DB_ERROR_FEATURE_NOT_AVAILABLE, null, 'null', "getLastID with " . PEAR_DATABASE . ' database.', 'G_Error', true);
         DBconnection::logError($dberror, DB_ERROR_SHOWALL_AND_STOP);
         //this error will stop the execution, until we add this feature!!
         return $dberror;
     }
     return mysql_insert_id();
 }