Example #1
0
 public function execute($filePath)
 {
     clearstatcache();
     if (!is_file($filePath)) {
         $message = __METHOD__ . "() no such file or directory.";
         throw new Sabel_Exception_FileNotFound($message);
     }
     $this->filePath = $filePath;
     $file = basename($filePath);
     @(list($num, $mdlName, $command) = explode("_", $file));
     if ($mdlName === "query.php") {
         $command = "query";
     } else {
         $command = str_replace(".php", "", $command);
     }
     $this->version = $num;
     $this->mdlName = $mdlName;
     $this->tblName = convert_to_tablename($mdlName);
     if ($this->hasMethod($command)) {
         $this->{$command}();
     } else {
         $message = __METHOD__ . "() command '{$command}' not found.";
         throw new Sabel_Db_Exception($message);
     }
 }
Example #2
0
 private function dropSequence($incCol)
 {
     if ($incCol !== null) {
         $tblName = convert_to_tablename($this->mdlName);
         $seqName = strtoupper($tblName) . "_" . strtoupper($incCol) . "_SEQ";
         $this->executeQuery("DROP SEQUENCE " . $seqName);
     }
 }
Example #3
0
 /**
  * @param string $column
  */
 public function __construct($column)
 {
     if (strpos($column, ".") === false) {
         $this->column = $column;
     } else {
         list($mdlName, $column) = explode(".", $column);
         $this->column = convert_to_tablename($mdlName) . "." . $column;
     }
 }
Example #4
0
 protected function addColumn()
 {
     $columns = $this->getReader()->readAddColumn()->getColumns();
     if (Sabel_Db_Migration_Manager::isUpgrade()) {
         $this->execAddColumn($columns);
     } else {
         $tblName = convert_to_tablename($this->mdlName);
         $quotedTblName = $this->quoteIdentifier($tblName);
         foreach ($columns as $column) {
             $this->dropDefaultConstraint($tblName, $column->name);
             $colName = $this->quoteIdentifier($column->name);
             $this->executeQuery("ALTER TABLE {$tblName} DROP COLUMN {$colName}");
         }
     }
 }
Example #5
0
 protected function quoteIdentifierForOrderBy($orders)
 {
     $results = array();
     foreach ($orders as $column => $order) {
         $mode = strtoupper($order["mode"]);
         //$nulls = strtoupper($order["nulls"]);
         if (($pos = strpos($column, ".")) !== false) {
             $tblName = convert_to_tablename(substr($column, 0, $pos));
             $column = $this->quoteIdentifier($tblName) . "." . $this->quoteIdentifier(substr($column, $pos + 1));
         } else {
             $column = $this->quoteIdentifier($column);
         }
         //$_nulls    = ($nulls === "FIRST") ? "IS NOT NULL" : "IS NULL";
         $results[] = "{$column} {$mode}";
     }
     return implode(", ", $results);
 }
Example #6
0
 protected function quoteIdentifierForOrderBy($orders)
 {
     $results = array();
     foreach ($orders as $column => $mode) {
         if (($pos = strpos($column, ".")) !== false) {
             $tblName = convert_to_tablename(substr($column, 0, $pos));
             $results[] = $this->quoteIdentifier($tblName) . "." . $this->quoteIdentifier(substr($column, $pos + 1)) . " " . $mode;
         } else {
             $results[] = $this->quoteIdentifier($column) . " " . $mode;
         }
     }
     return implode(", ", $results);
 }
Example #7
0
 /**
  * @param string $mdlName
  *
  * @return void
  */
 protected function initialize($mdlName = null)
 {
     if ($mdlName === null) {
         $mdlName = get_class($this);
     }
     $this->modelName = $mdlName;
     if ($this->tableName === "") {
         $this->tableName = convert_to_tablename($mdlName);
     }
     $this->metadata = Sabel_Db_Metadata::getTableInfo($this->tableName, $this->connectionName);
     $this->metaCols = $this->metadata->getColumns();
 }
Example #8
0
 protected function createProjection(Sabel_Db_Statement $stmt)
 {
     if (empty($this->projection)) {
         $projection = array();
         foreach ($this->objects as $object) {
             $projection = array_merge($projection, $object->getProjection($stmt));
         }
         $quotedTblName = $stmt->quoteIdentifier($this->tblName);
         foreach ($this->model->getColumnNames() as $column) {
             $projection[] = $quotedTblName . "." . $stmt->quoteIdentifier($column);
         }
     } else {
         $projection = array();
         foreach ($this->projection as $name => $proj) {
             if (($tblName = convert_to_tablename($name)) === $this->tblName) {
                 foreach ($proj as $column) {
                     $projection[] = $stmt->quoteIdentifier($tblName) . "." . $stmt->quoteIdentifier($column);
                 }
             } else {
                 foreach ($proj as $column) {
                     $as = "{$tblName}.{$column}";
                     if (strlen($as) > 30) {
                         $as = Sabel_Db_Join_ColumnHash::toHash($as);
                     }
                     $p = $stmt->quoteIdentifier($tblName) . "." . $stmt->quoteIdentifier($column);
                     $projection[] = $p . " AS " . $stmt->quoteIdentifier($as);
                 }
             }
         }
     }
     return implode(", ", $projection);
 }