コード例 #1
0
ファイル: Metadata.php プロジェクト: hamaco/phwittr-on-xoops
 public static function getTableInfo($tblName, $connectionName = "default")
 {
     if (isset(self::$metadata[$tblName])) {
         return self::$metadata[$tblName];
     }
     $className = "Schema_" . convert_to_modelname($tblName);
     if (Sabel::using($className)) {
         $cols = array();
         $schemaClass = new $className();
         foreach ($schemaClass->get() as $colName => $info) {
             $co = new Sabel_Db_Metadata_Column();
             $co->name = $colName;
             foreach ($info as $key => $val) {
                 $co->{$key} = $val;
             }
             $cols[$colName] = $co;
         }
         $tblSchema = new Sabel_Db_Metadata_Table($tblName, $cols);
         $properties = $schemaClass->getProperty();
         $tblSchema->setTableEngine($properties["tableEngine"]);
         $tblSchema->setUniques($properties["uniques"]);
         $tblSchema->setForeignKeys($properties["fkeys"]);
     } else {
         $schemaObj = Sabel_Db::createMetadata($connectionName);
         $tblSchema = $schemaObj->getTable($tblName);
     }
     return self::$metadata[$tblName] = $tblSchema;
 }
コード例 #2
0
ファイル: Metadata.php プロジェクト: reoring/sabel
 public function getTable($tblName)
 {
     $columns = $this->createColumns($tblName);
     $schema = new Sabel_Db_Metadata_Table($tblName, $columns);
     $schema->setForeignKeys($this->getForeignKeys($tblName));
     $schema->setUniques($this->getUniques($tblName));
     return $schema;
 }
コード例 #3
0
ファイル: Model.php プロジェクト: hamaco/phwittr-on-xoops
 /**
  * @param Sabel_Db_Statement $stmt
  * @param array $values
  *
  * @return Sabel_Db_Statement
  */
 protected function prepareInsert(Sabel_Db_Statement $stmt, array $values = array())
 {
     if (empty($values)) {
         $values = $this->values;
     }
     return $stmt->values($values)->sequenceColumn($this->metadata->getSequenceColumn());
 }
コード例 #4
0
ファイル: Statement.php プロジェクト: hamaco/phwittr-on-xoops
 protected function getProjection()
 {
     if (empty($this->projection)) {
         $colNames = $this->quoteIdentifier($this->metadata->getColumnNames());
         return implode(", ", $colNames);
     } elseif (is_string($this->projection)) {
         return $this->projection;
     } else {
         $ps = array();
         foreach ($this->projection as $p) {
             $ps[] = $this->quoteIdentifier($p);
         }
         return implode(", ", $ps);
     }
 }
コード例 #5
0
ファイル: FileWriter.php プロジェクト: reoring/sabel
 public function write(Sabel_Db_Metadata_Table $metadata)
 {
     $mdlName = convert_to_modelname($metadata->getTableName());
     $className = "Schema_" . $mdlName;
     $target = $this->schemaDir . DS . $mdlName . ".php";
     if (file_exists($target)) {
         unlink($target);
     }
     $lines = array();
     $lines[] = "<?php" . PHP_EOL;
     $lines[] = "class {$className}";
     $lines[] = "{";
     $lines[] = "  public static function get()";
     $lines[] = "  {";
     $lines[] = '    $cols = array();' . PHP_EOL;
     $colLines = $this->createColumnLines($metadata);
     foreach ($colLines as $line) {
         $lines[] = "    " . $line;
     }
     $lines[] = PHP_EOL;
     $lines[] = '    return $cols;';
     $lines[] = "  }" . PHP_EOL;
     $lines[] = "  public function getProperty()";
     $lines[] = "  {";
     $lines[] = '    $property = array();' . PHP_EOL;
     $this->writeEngine($lines, $metadata);
     $this->writeUniques($lines, $metadata);
     $this->writeForeignKeys($lines, $metadata);
     $lines[] = PHP_EOL;
     $lines[] = "    return \$property;";
     $lines[] = "  }";
     $lines[] = "}";
     $fp = fopen($target, "w");
     fwrite($fp, implode(PHP_EOL, $lines));
     fclose($fp);
 }