Пример #1
0
 public function testInsertRecordInReadonly()
 {
     return;
     $logs = new LogSql('unit', Relation::r()->findByName('logs.Logs'), array('DEFAULT', 'DEFAULT', 'TG_OP::"logs"."enum_op_type"'));
     $db = Connection::factory('RW');
     $logs->build($db);
     // insert
     $this->assertSame($this->getNumberRowsInTable('unit.readonly'), 0);
     $this->assertSame($this->getNumberRowsInTable('logs.readonly'), 0);
     $db->query(new Raw("INSERT INTO readonly( name ) VALUES ( 'peter' );"));
     $this->assertSame($this->getNumberRowsInTable('unit.readonly'), 1);
     $this->assertSame($this->getNumberRowsInTable('logs.readonly'), 1);
     $db->query(new Raw("UPDATE readonly SET name = 'matt'"));
     $this->assertSame($this->getNumberRowsInTable('unit.readonly'), 1);
     $this->assertSame($this->getNumberRowsInTable('logs.readonly'), 2);
     $db->query(new Raw("DELETE FROM readonly WHERE name = 'matt'"));
     $this->assertSame($this->getNumberRowsInTable('unit.readonly'), 0);
     $this->assertSame($this->getNumberRowsInTable('logs.readonly'), 3);
     try {
         $db->query(new Raw("DELETE FROM \"logs\".readonly"));
         $this->fail("Exception expected");
     } catch (\Exception $e) {
     }
     $this->assertSame($this->getNumberRowsInTable('logs.readonly'), 3);
     try {
         $db->query(new Raw("UPDATE \"logs\".readonly SET name = 'jim'"));
         $this->fail("Exception expected");
     } catch (\Exception $e) {
     }
     $this->assertSame($this->getNumberRowsInTable('logs.readonly'), 3);
 }
Пример #2
0
 private function catalogRefresh()
 {
     Relation::r()->preload();
     Attribute::r()->preload();
     Index::r()->preload();
     Type::r()->preload();
 }
Пример #3
0
 /**
  * See, http://www.postgresql.org/docs/8.4/interactive/catalog-pg-constraint.html
  * @return bool. Populate the static variables $this->references $this->isReferencedBy
  */
 private function preloadReferences()
 {
     // References defined in pg_catalog
     $sql = 'SELECT * FROM dev."vAttributeReferences" WHERE "isInherited" = false';
     $relationships = $this->db->query(new Query($sql));
     foreach ($relationships->fetch() as $relationship) {
         $fk = $this->instancesPersisted[$relationship['fk_key']];
         $pk = $this->instancesPersisted[$relationship['pk_key']];
         if (!$fk or !$pk) {
             d_pr($relationship);
             die;
         }
         // slower alternatives. They all do the same thing
         // $fk = $this->persistedGet()->findOneByKey( $relationship['fk_key'] );
         // $pk = $this->persistedGet()->findOneByKey( $relationship['pk_key'] );
         // $fk = $this->find( $relationship['fk_key'] );
         // $pk = $this->find( $relationship['pk_key'] );
         $fk->addReference($pk);
     }
     // look for normality defined relationships
     $profiler = new Profiler(__FUNCTION__);
     $profiler->log();
     foreach (EntityRelation::r()->findAll() as $relation) {
         $tags = $relation->getNormalityTags();
         if (isset($tags['references'])) {
             foreach ($tags['references'] as $reference) {
                 $reference = array_map('trim', explode('=', $reference));
                 $fk = $this->findByRelation($relation)->findOneByName($reference[0]);
                 $pk = $this->findByIdentifier($reference[1]);
                 // go the database to get child records, using the Relation repo methods causes a infinite preload loop
                 $query = new Query("SELECT oid::text || '.' || %attnum:int%::text FROM dev.relationDescendants( %oid:int%::oid ) as _ ( oid );", array('attnum' => $pk->get('attnum'), 'oid' => $pk->getRelation()->get('oid')));
                 foreach ($this->db->query($query)->fetch() as $pk_key) {
                     $fk->addReference($this->find($pk_key));
                 }
             }
         }
     }
     //        echo $profiler->log()->output();
 }