Пример #1
0
 function test_query_tool_load_current()
 {
     $rd = new Dataface_QueryTool('Profiles', $this->table1->db, array());
     $s = $rd->loadCurrent();
     $this->assertTrue(is_a($s, 'Dataface_Record'));
     // should load all columns except the blobs
     $this->assertEquals($s->getValue('id'), 10);
     $this->assertEquals($s->getValue('fname'), 'John');
     $this->assertEquals($s->getValueAsString('lastlogin'), '2005-06-30 00:00:00');
     //		$this->assertTrue(!$s->hasValue('photo'), 'Photo should not have an associated value. Blobs should not be loaded by the result descriptor');
     $this->assertTrue($s->hasValue('photo_mimetype'), 'Photo mimetype should have a value.');
     $this->assertEquals($rd->found(), 3);
     $this->assertEquals($rd->cardinality(), 3);
     $this->assertEquals($rd->cursor(), 0);
     $this->assertEquals($rd->start(), 0);
     $this->assertEquals($rd->end(), 2);
     // now try to specify a cursor
     $rd2 = new Dataface_QueryTool('Profiles', $this->table1->db, array('-cursor' => '1'));
     $s = $rd2->loadCurrent();
     $this->assertTrue(is_a($s, 'Dataface_Record'));
     $this->assertEquals($s->getValue('id'), 11);
     $this->assertEquals($s->getValue('fname'), 'Johnson');
     $this->assertEquals($s->getValueAsString('lastlogin'), '2005-06-30 00:00:00');
     $this->assertEquals($rd2->found(), 3);
     $this->assertEquals($rd2->cardinality(), 3);
     $this->assertEquals($rd2->cursor(), 1);
     $this->assertEquals($rd2->start(), 0);
     $this->assertEquals($rd2->end(), 2);
     $rd2 = new Dataface_QueryTool('Profiles', $this->table1->db, array('-cursor' => 1, '-limit' => 2));
     $s = $rd2->loadCurrent();
     $this->assertTrue(is_a($s, 'Dataface_Record'));
     $this->assertEquals($s->getValue('id'), 11);
     $this->assertEquals($s->getValue('fname'), 'Johnson');
     $this->assertEquals($s->getValueAsString('lastlogin'), '2005-06-30 00:00:00');
     $this->assertEquals($rd2->found(), 3);
     $this->assertEquals($rd2->cardinality(), 3);
     $this->assertEquals($rd2->cursor(), 1);
     $this->assertEquals($rd2->start(), 0);
     $this->assertEquals($rd2->end(), 1);
     $rd2 = new Dataface_QueryTool('Profiles', $this->table1->db, array('-cursor' => 1, '-limit' => 2, 'fname' => 'John'));
     $s = $rd2->loadCurrent();
     $this->assertTrue(is_a($s, 'Dataface_Record'));
     $this->assertEquals($s->getValue('id'), 11);
     $this->assertEquals($s->getValue('fname'), 'Johnson');
     $this->assertEquals($s->getValueAsString('lastlogin'), '2005-06-30 00:00:00');
     $this->assertEquals($rd2->found(), 2);
     $this->assertEquals($rd2->cardinality(), 3);
     $this->assertEquals($rd2->cursor(), 1);
     $this->assertEquals($rd2->start(), 0);
     $this->assertEquals($rd2->end(), 1);
     $rd2 = new Dataface_QueryTool('Profiles', $this->table1->db, array('-cursor' => 0, '-limit' => 2, 'fname' => '=John'));
     $s = $rd2->loadCurrent();
     $this->assertTrue(is_a($s, 'Dataface_Record'));
     $this->assertEquals($s->getValue('id'), 10);
     $this->assertEquals($s->getValue('fname'), 'John');
     $this->assertEquals($s->getValueAsString('lastlogin'), '2005-06-30 00:00:00');
     $this->assertEquals($rd2->found(), 1);
     $this->assertEquals($rd2->cardinality(), 3);
     $this->assertEquals($rd2->cursor(), 0);
     $this->assertEquals($rd2->start(), 0);
     $this->assertEquals($rd2->end(), 0);
 }
Пример #2
0
 public function loadRecords(xatacard_layout_Schema $schema, $query)
 {
     $tablename = $schema->getProperty('table');
     if (!$tablename) {
         throw new Exception(sprintf("MySQL datasource cannot load a records from schema '%s' because the schema does not specify a table", $schema->getLabel()));
     }
     $queryTool = new Dataface_QueryTool($tablename, df_db(), $query);
     $res = $queryTool->loadSet('', true, true, false);
     // preview should be disabled... we need full records
     if (PEAR::isError($res)) {
         throw new Exception(sprintf("MySQL datasource failed to load records: %s", $res->getMessage()));
     }
     $out = new xatacard_layout_RecordSet();
     $out->setSchema($schema);
     $out->setDatasource($this);
     $out->setFound($queryTool->found());
     $out->setCardinality($queryTool->cardinality());
     $out->setStart($queryTool->start());
     $out->setEnd($queryTool->end());
     $out->setLimit($queryTool->limit());
     $records = $queryTool->getRecordsArray();
     if (PEAR::isError($records)) {
         throw new Exception(sprintf("MySQL datasource cannot load records from schema '%s' because an error occurred in the query: %s", $schema->getLabel(), $records->getMessage()));
     }
     foreach ($records as $rec) {
         $out->addRecord($this->buildRecord($schema, $rec));
     }
     return $out;
 }