Esempio n. 1
0
 /**
  * @param $schemas
  */
 public function fillRuleTables(&$schemas)
 {
     $this->em->clear();
     //Rules
     $sql = "SELECT r.rulename as oid,\n                                r.rulename as name,\n                                trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)) as detail,\n                                ev_enabled as enabled,\n                                n.nspname as schema,\n                                r.ev_class as table,\n                                c.relname as table_name\n                        FROM pg_catalog.pg_rewrite r\n                          INNER JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n                          INNER JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n                        WHERE  c.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(c.oid)\n                        ORDER BY 1";
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('oid', 'oid');
     $rsm->addScalarResult('name', 'name');
     $rsm->addScalarResult('detail', 'detail');
     $rsm->addScalarResult('enabled', 'enabled');
     $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) {
         $rule = new Rule($row['schema'], $row['table']);
         foreach ($row as $key => $value) {
             $rule->__set($key, $value);
         }
         if ($this->index_type == PgRetriever::INDEX_TYPE_OID) {
             $schemas[$row['schema']]->addTableRule($row['table'], $rule);
         } elseif ($this->index_type == PgRetriever::INDEX_TYPE_NAME) {
             $schemas[$row['schema']]->addTableRule($row['table_name'], $rule);
         }
         unset($rule);
     }
     unset($stmt);
 }
Esempio n. 2
0
 /**
  * @param $schema
  * @param $tableOid
  * @return array
  */
 public function getRules($schema, $tableOid)
 {
     //Rules
     $sql = "SELECT r.rulename as oid,\n                                r.rulename as name,\n                                trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)) as detail,\n                                ev_enabled as enabled\n                        FROM pg_catalog.pg_rewrite r\n                        WHERE r.ev_class = '" . pg_escape_string($tableOid) . "'\n                        ORDER BY 1";
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('oid', 'oid');
     $rsm->addScalarResult('name', 'name');
     $rsm->addScalarResult('detail', 'detail');
     $rsm->addScalarResult('enabled', 'enabled');
     $stmt = $this->em->createNativeQuery($sql, $rsm);
     $stmt->useResultCache(true, self::CACHE_LIFETIME);
     $rules = [];
     foreach ($stmt->getResult(AbstractQuery::HYDRATE_ARRAY) as $row) {
         $rule = new Rule($schema, $tableOid);
         foreach ($row as $key => $value) {
             $rule->__set($key, $value);
         }
         if ($this->index_type == self::INDEX_TYPE_OID) {
             $rules[$row['oid']] = $rule;
         } elseif ($this->index_type == self::INDEX_TYPE_NAME) {
             $rules[$row['name']] = $rule;
         }
     }
     return $rules;
 }