コード例 #1
0
 /**
  * Searches for tables in the database. Maybe we want to search also the views.
  * @param	Database $database The Database model class to add tables to.
  */
 public function parse(Database $database, PDOTask $task = null)
 {
     $tables = array();
     $stmt = $this->dbh->query("SELECT OBJECT_NAME FROM USER_OBJECTS WHERE OBJECT_TYPE = 'TABLE'");
     $task->log("Reverse Engineering Table Structures");
     // First load the tables (important that this happen before filling out details of tables)
     while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
         if (strpos($row['OBJECT_NAME'], '$') !== false) {
             // this is an Oracle internal table or materialized view - prune
             continue;
         }
         $table = new Table($row['OBJECT_NAME']);
         $task->log("Adding table '" . $table->getName() . "'");
         $database->addTable($table);
         // Add columns, primary keys and indexes.
         $this->addColumns($table);
         $this->addPrimaryKey($table);
         $this->addIndexes($table);
         $tables[] = $table;
     }
     $task->log("Reverse Engineering Foreign Keys");
     foreach ($tables as $table) {
         $task->log("Adding foreign keys for table '" . $table->getName() . "'");
         $this->addForeignKeys($table);
     }
     return count($tables);
 }
コード例 #2
0
 /**
  *
  */
 public function parse(Database $database, PDOTask $task = null)
 {
     $this->addVendorInfo = $this->getGeneratorConfig()->getBuildProperty('addVendorInfo');
     $stmt = $this->dbh->query("SHOW TABLES");
     // First load the tables (important that this happen before filling out details of tables)
     $tables = array();
     $task->log("Reverse Engineering Tables");
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $name = $row[0];
         $task->log("  Adding table '" . $name . "'");
         $table = new Table($name);
         $database->addTable($table);
         $tables[] = $table;
     }
     // Now populate only columns.
     $task->log("Reverse Engineering Columns");
     foreach ($tables as $table) {
         $task->log("  Adding columns for table '" . $table->getName() . "'");
         $this->addColumns($table);
     }
     // Now add indices and constraints.
     $task->log("Reverse Engineering Indices And Constraints");
     foreach ($tables as $table) {
         $task->log("  Adding indices and constraints for table '" . $table->getName() . "'");
         $this->addForeignKeys($table);
         $this->addIndexes($table);
         $this->addPrimaryKey($table);
         if ($this->addVendorInfo) {
             $this->addTableVendorInfo($table);
         }
     }
     return count($tables);
 }
コード例 #3
0
 /**
  *
  */
 public function parse(Database $database, PDOTask $task = null)
 {
     $stmt = $this->dbh->query("SELECT version() as ver");
     $nativeVersion = $stmt->fetchColumn();
     if (!$nativeVersion) {
         throw new EngineException("Failed to get database version");
     }
     $arrVersion = sscanf($nativeVersion, '%*s %d.%d');
     $version = sprintf("%d.%d", $arrVersion[0], $arrVersion[1]);
     // Clean up
     $stmt = null;
     $stmt = $this->dbh->query("SELECT c.oid,\n\t\t\t\t\t\t\t\t    case when n.nspname='public' then c.relname else n.nspname||'.'||c.relname end as relname\n\t\t\t\t\t\t\t\t    FROM pg_class c join pg_namespace n on (c.relnamespace=n.oid)\n\t\t\t\t\t\t\t\t    WHERE c.relkind = 'r'\n\t\t\t\t\t\t\t\t      AND n.nspname NOT IN ('information_schema','pg_catalog')\n\t\t\t\t\t\t\t\t      AND n.nspname NOT LIKE 'pg_temp%'\n\t\t\t\t\t\t\t\t      AND n.nspname NOT LIKE 'pg_toast%'\n\t\t\t\t\t\t\t\t    ORDER BY relname");
     $tableWraps = array();
     // First load the tables (important that this happen before filling out details of tables)
     $task->log("Reverse Engineering Tables");
     while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
         $name = $row['relname'];
         $task->log("  Adding table '" . $name . "'");
         $oid = $row['oid'];
         $table = new Table($name);
         $database->addTable($table);
         // Create a wrapper to hold these tables and their associated OID
         $wrap = new stdClass();
         $wrap->table = $table;
         $wrap->oid = $oid;
         $tableWraps[] = $wrap;
     }
     // Now populate only columns.
     $task->log("Reverse Engineering Columns");
     foreach ($tableWraps as $wrap) {
         $task->log("  Adding columns for table '" . $wrap->table->getName() . "'");
         $this->addColumns($wrap->table, $wrap->oid, $version);
     }
     // Now add indexes and constraints.
     $task->log("Reverse Engineering Indices And Constraints");
     foreach ($tableWraps as $wrap) {
         $task->log("  Adding indices and constraints for table '" . $wrap->table->getName() . "'");
         $this->addForeignKeys($wrap->table, $wrap->oid, $version);
         $this->addIndexes($wrap->table, $wrap->oid, $version);
         $this->addPrimaryKey($wrap->table, $wrap->oid, $version);
     }
     // TODO - Handle Sequences ...
     return count($tableWraps);
 }