Ejemplo n.º 1
0
 function listTables()
 {
     $sql = "select t.table_name from information_schema.tables t  where t.table_schema = 'public' order by t.table_name";
     $q = \hatwebtech\dal\DAL::query();
     $q->queryStmt($sql);
     $dbg['tables'] = $q->getResultsDbRow();
     $tables = array();
     foreach ($dbg['tables'] as $t) {
         //echo "    '{$t['table_name']}',\n";
         $tables[] = $t['table_name'];
     }
     //\hat\dbg::alert($dbg);
     return $tables;
 }
Ejemplo n.º 2
0
 /**
  *  delete
  * @todo unset from $this->_results
  * @todo unset from $this->_has_many_for_save
  */
 public function delete()
 {
     if ($this->_behave('pre_delete') === false) {
         //echo 'pre_delete exit';
         //return false; // is FALSE right response in case of skiping delete???
     }
     $this->preDelete();
     if (empty($this->_primaryKeys)) {
         echo 'no primary keys';
         return false;
     }
     if (!isset($this->_query)) {
         $this->_query = \hatwebtech\dal\DAL::query();
     }
     $this->_query->delete($this->_getModelName());
     foreach ($this->_primaryKeys as $primary_key) {
         if ($this->get($this->_getHumanFieldName($primary_key) . 'Exists', array())) {
             $this->_query->andWhere("{$primary_key} =?", $this->get($this->_getHumanFieldName($primary_key), array()));
         } else {
             throw new \Exception('Error deleting ' . $this->_getModelName() . '; ' . $primary_key . ' not set.');
         }
     }
     //print_r($this->_query->queryDebug()); exit;
     $r1 = $this->_query->queryStmt();
     if ($r1 === false) {
         $r1 = $this->_query->getLastPdoErrorMessage();
         //$r1 = $this->_query->getPdoErrorMessages();
         throw new \Exception('Error deleting ' . $this->_getModelName() . ' with message: ' . $r1);
         return false;
     }
     $this->postDelete();
     $this->_behave('post_delete');
     return true;
 }