Ejemplo n.º 1
0
 public function handleError($model, $query, \PDOException $e)
 {
     // echo "*** Model in handleError: " . $model . "\n";
     switch ($e->getCode()) {
         // MySQL table missing
         case '42S02':
             // SQLite table missing
         // SQLite table missing
         case 'HY000' && stripos($e->getMessage(), "no such table") !== false:
             if ($model != 'StdClass') {
                 $instance = new $model();
                 if ($instance instanceof ActiveRecord) {
                     $table_builder = new TableBuilder($instance);
                     $table_builder->build();
                     return $this->query($query, $model);
                     // Re-run the query
                 }
             }
             throw new DatabaseLayer\TableDoesntExistException($e->getCode() . ": " . $e->getMessage());
         default:
             // Write exception to log.
             if (DatabaseLayer::getInstance()->getLogger()) {
                 DatabaseLayer::getInstance()->getLogger()->addError("Active Record Exception in " . $model . "\n\n" . $e->getCode() . ": " . $e->getMessage() . "\n\nrunning:\n\n{$query}");
             }
             throw new DatabaseLayer\Exception($e->getCode() . ": " . $e->getMessage() . ".\n\n" . $query);
     }
 }
Ejemplo n.º 2
0
 /**
  * Delete the selected records table.
  * WARNING YO.
  */
 public static function deleteTable()
 {
     $class = get_called_class();
     $object = new $class();
     $table_builder = new TableBuilder($object);
     $table_builder->destroy();
 }