コード例 #1
0
 public function fetch($fetch_style = PDO::FETCH_ASSOC, $cursor_orientation = PDO::FETCH_ORI_NEXT, $cursor_offset = 0)
 {
     /*
           if ($this->cache_read === true) {
             list(, $this->result) = each($this->cache_data);
           } else {
     */
     $this->result = parent::fetch($fetch_style, $cursor_orientation, $cursor_offset);
     /*
             if (isset($this->cache_key)) {
               $this->cache_data[] = $this->result;
             }
           }
     */
     return $this->result;
 }
コード例 #2
0
 public function execute($input_parameters = array())
 {
     $query_action = strtolower(substr($this->queryString, 0, strpos($this->queryString, ' ')));
     $db_table_prefix = OSCOM::getConfig('db_table_prefix');
     if ($query_action == 'delete') {
         $query_data = explode(' ', $this->queryString, 4);
         $query_table = substr($query_data[2], strlen($db_table_prefix));
         if ($this->_pdo->hasForeignKey($query_table)) {
             // check for RESTRICT constraints first
             foreach ($this->_pdo->getForeignKeys($query_table) as $fk) {
                 if ($fk['on_delete'] == 'restrict') {
                     $Qchild = $this->_pdo->prepare('select ' . $fk['to_field'] . ' from ' . $query_data[2] . ' ' . $query_data[3]);
                     foreach ($this->_binded_params as $key => $value) {
                         $Qchild->bindValue($key, $value['value'], $value['data_type']);
                     }
                     $Qchild->execute();
                     while ($Qchild->fetch()) {
                         $Qcheck = $this->_pdo->prepare('select ' . $fk['from_field'] . ' from ' . $db_table_prefix . $fk['from_table'] . ' where ' . $fk['from_field'] . ' = "' . $Qchild->value($fk['to_field']) . '" limit 1');
                         $Qcheck->execute();
                         if (count($Qcheck->fetchAll()) === 1) {
                             trigger_error('RESTRICT constraint condition from table ' . $db_table_prefix . $fk['from_table']);
                             return false;
                         }
                     }
                 }
             }
             foreach ($this->_pdo->getForeignKeys($query_table) as $fk) {
                 $Qparent = $this->_pdo->prepare('select * from ' . $query_data[2] . ' ' . $query_data[3]);
                 foreach ($this->_binded_params as $key => $value) {
                     $Qparent->bindValue($key, $value['value'], $value['data_type']);
                 }
                 $Qparent->execute();
                 while ($Qparent->fetch()) {
                     if ($fk['on_delete'] == 'cascade') {
                         $Qdel = $this->_pdo->prepare('delete from ' . $db_table_prefix . $fk['from_table'] . ' where ' . $fk['from_field'] . ' = :' . $fk['from_field']);
                         $Qdel->bindValue(':' . $fk['from_field'], $Qparent->value($fk['to_field']));
                         $Qdel->execute();
                     } elseif ($fk['on_delete'] == 'set_null') {
                         $Qupdate = $this->_pdo->prepare('update ' . $db_table_prefix . $fk['from_table'] . ' set ' . $fk['from_field'] . ' = null where ' . $fk['from_field'] . ' = :' . $fk['from_field']);
                         $Qupdate->bindValue(':' . $fk['from_field'], $Qparent->value($fk['to_field']));
                         $Qupdate->execute();
                     }
                 }
             }
         }
     } elseif ($query_action == 'update') {
         $query_data = explode(' ', $this->queryString, 3);
         $query_table = substr($query_data[1], strlen($db_table_prefix));
         if ($this->_pdo->hasForeignKey($query_table)) {
             // check for RESTRICT constraints first
             foreach ($this->_pdo->getForeignKeys($query_table) as $fk) {
                 if ($fk['on_update'] == 'restrict') {
                     $Qchild = $this->_pdo->prepare('select ' . $fk['to_field'] . ' from ' . $query_data[2] . ' ' . $query_data[3]);
                     foreach ($this->_binded_params as $key => $value) {
                         $Qchild->bindValue($key, $value['value'], $value['data_type']);
                     }
                     $Qchild->execute();
                     while ($Qchild->fetch()) {
                         $Qcheck = $this->_pdo->prepare('select ' . $fk['from_field'] . ' from ' . $db_table_prefix . $fk['from_table'] . ' where ' . $fk['from_field'] . ' = "' . $Qchild->value($fk['to_field']) . '" limit 1');
                         $Qcheck->execute();
                         if (count($Qcheck->fetchAll()) === 1) {
                             trigger_error('RESTRICT constraint condition from table ' . $db_table_prefix . $fk['from_table']);
                             return false;
                         }
                     }
                 }
             }
             foreach ($this->_pdo->getForeignKeys($query_table) as $fk) {
                 // check to see if foreign key column value is being changed
                 if (strpos(substr($this->queryString, strpos($this->queryString, ' set ') + 4, strpos($this->queryString, ' where ') - strpos($this->queryString, ' set ') - 4), ' ' . $fk['to_field'] . ' ') !== false) {
                     $Qparent = $this->_pdo->prepare('select * from ' . $query_data[1] . substr($this->queryString, strrpos($this->queryString, ' where ')));
                     foreach ($this->_binded_params as $key => $value) {
                         if (preg_match('/:\\b' . substr($key, 1) . '\\b/', $Qparent->queryString)) {
                             $Qparent->bindValue($key, $value['value'], $value['data_type']);
                         }
                     }
                     $Qparent->execute();
                     while ($Qparent->fetch()) {
                         if ($fk['on_update'] == 'cascade' || $fk['on_update'] == 'set_null') {
                             $on_update_value = '';
                             if ($fk['on_update'] == 'cascade') {
                                 $on_update_value = $this->_binded_params[':' . $fk['to_field']]['value'];
                             }
                             $Qupdate = $this->_pdo->prepare('update ' . $db_table_prefix . $fk['from_table'] . ' set ' . $fk['from_field'] . ' = :' . $fk['from_field'] . ' where ' . $fk['from_field'] . ' = :' . $fk['from_field'] . '_orig');
                             if (empty($on_update_value)) {
                                 $Qupdate->bindNull(':' . $fk['from_field']);
                             } else {
                                 $Qupdate->bindValue(':' . $fk['from_field'], $on_update_value);
                             }
                             $Qupdate->bindValue(':' . $fk['from_field'] . '_orig', $Qparent->value($fk['to_field']));
                             $Qupdate->execute();
                         }
                     }
                 }
             }
         }
     }
     return parent::execute($input_parameters);
 }
コード例 #3
0
 public function fetchAll($fetch_style = PDO::FETCH_ASSOC, $fetch_argument = null, $ctor_args = array())
 {
     if ($this->_cache_read === true) {
         $this->result = $this->_cache_data;
     } else {
         // fetchAll() fails if second argument is passed in a fetch style that does not
         // use the optional argument
         if (in_array($fetch_style, array(PDO::FETCH_COLUMN, PDO::FETCH_CLASS, PDO::FETCH_FUNC))) {
             $this->result = parent::fetchAll($fetch_style, $fetch_argument, $ctor_args);
         } else {
             $this->result = parent::fetchAll($fetch_style);
         }
         if (isset($this->_cache_key)) {
             $this->_cache_data = $this->result;
         }
     }
     return $this->result;
 }