Exemplo n.º 1
0
 /**
  * @param $schemas
  */
 public function fillChildTables(&$schemas)
 {
     $this->em->clear();
     //Child tables
     $sql = " SELECT c.oid,\n                        c.oid::pg_catalog.regclass as name,\n                        i.inhparent as table,\n                        c2.relname as table_name,\n                        n.nspname as schema\n                FROM pg_catalog.pg_class c\n                  INNER JOIN pg_catalog.pg_inherits i ON c.oid = i.inhparent\n                  INNER JOIN pg_catalog.pg_class c2 ON c2.oid = i.inhparent\n                  INNER JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n                WHERE c2.relkind = 'r'\n                    AND n.nspname <> 'pg_catalog'\n                   AND n.nspname <> 'information_schema'\n                   AND n.nspname !~ '^pg_toast'\n                   AND n.nspname !~ '^pg_temp'\n                   AND n.nspname <> 'londiste'\n                   AND n.nspname <> 'pgq'\n                    --AND pg_catalog.pg_table_is_visible(c2.oid)\n                ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text";
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('oid', 'oid');
     $rsm->addScalarResult('name', 'name');
     $rsm->addScalarResult('schema', 'schema');
     $rsm->addScalarResult('table', 'table');
     $rsm->addScalarResult('table_name', 'table_name');
     $stmt = $this->em->createNativeQuery($sql, $rsm);
     $stmt->useResultCache(true, PgRetriever::CACHE_LIFETIME);
     foreach ($stmt->getResult(AbstractQuery::HYDRATE_ARRAY) as $row) {
         $child = new ChildTable($row['schema'], $row['table']);
         foreach ($row as $key => $value) {
             $child->__set($key, $value);
         }
         if ($this->index_type == PgRetriever::INDEX_TYPE_OID) {
             $schemas[$row['schema']]->addTableChildTable($row['table'], $child);
         } elseif ($this->index_type == PgRetriever::INDEX_TYPE_NAME) {
             $schemas[$row['schema']]->addTableChildTable($row['table_name'], $child);
         }
         unset($child);
     }
     unset($stmt);
 }
Exemplo n.º 2
0
 /**
  * @param $schema
  * @param $tableOid
  * @return array
  */
 public function getChildTables($schema, $tableOid)
 {
     //Child tables
     $sql = " SELECT c.oid,\n                            c.oid::pg_catalog.regclass as name\n                    FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n                    WHERE c.oid=i.inhrelid\n                        AND i.inhparent = '" . pg_escape_string($tableOid) . "'\n                    ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text";
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('oid', 'oid');
     $rsm->addScalarResult('name', 'name');
     $stmt = $this->em->createNativeQuery($sql, $rsm);
     $stmt->useResultCache(true, self::CACHE_LIFETIME);
     $childs = [];
     foreach ($stmt->getResult(AbstractQuery::HYDRATE_ARRAY) as $row) {
         $child = new ChildTable($schema, $tableOid);
         foreach ($row as $key => $value) {
             $child->__set($key, $value);
         }
         if ($this->index_type == self::INDEX_TYPE_OID) {
             $childs[$row['oid']] = $child;
         } elseif ($this->index_type == self::INDEX_TYPE_NAME) {
             $childs[$row['name']] = $child;
         }
     }
     return $childs;
 }