/**
  * delete all record corresponding to the conditions stored into the
  * jDaoConditions object.
  * @param jDaoConditions $searchcond
  * @return number of deleted rows
  * @since 1.0beta3
  */
 public final function deleteBy($searchcond)
 {
     if ($searchcond->isEmpty()) {
         return 0;
     }
     $query = 'DELETE FROM ' . $this->_conn->encloseName($this->_tables[$this->_primaryTable]['realname']) . ' WHERE ';
     $query .= $this->_createConditionsClause($searchcond, false);
     if ($this->_deleteByBeforeEvent) {
         jEvent::notify("daoDeleteByBefore", array('dao' => $this->_daoSelector, 'criterias' => $searchcond));
     }
     $result = $this->_conn->exec($query);
     if ($this->_deleteByAfterEvent) {
         jEvent::notify("daoDeleteByAfter", array('dao' => $this->_daoSelector, 'criterias' => $searchcond, 'result' => $result));
     }
     return $result;
 }
Exemple #2
0
 protected function _dropTable($name)
 {
     $this->conn->exec('DROP TABLE ' . $this->conn->encloseName($name));
 }
Exemple #3
0
 /**
  * execute a list of queries stored in a file
  * @param string $file path of the sql file
  */
 public function execSQLScript($file)
 {
     if (!isset($this->_conn->profile['table_prefix'])) {
         $prefix = '';
     } else {
         $prefix = $this->_conn->profile['table_prefix'];
     }
     $lines = file($file);
     $cmdSQL = '';
     $nbCmd = 0;
     $style = $this->dbmsStyle;
     foreach ((array) $lines as $key => $line) {
         if (!preg_match($style[0], $line) && strlen(trim($line)) > 0) {
             // The line isn't empty and isn't a comment
             //$line = str_replace("\\'","''",$line);
             //$line = str_replace($this->scriptReplaceFrom, $this->scriptReplaceBy,$line);
             $cmdSQL .= $line;
             if (preg_match($style[1], $line)) {
                 // If at the last line of the command, execute it
                 // Cleanup the command from the ending ";" and execute it
                 $cmdSQL = preg_replace($style[1], '', $cmdSQL);
                 $cmdSQL = str_replace('%%PREFIX%%', $prefix, $cmdSQL);
                 $this->_conn->exec($cmdSQL);
                 $nbCmd++;
                 $cmdSQL = '';
             }
         }
     }
     return $nbCmd;
 }