function test_query_tool_load_set() { $rd = new Dataface_QueryTool('Profiles', $this->table1->db, array()); $res = $rd->loadSet(); $this->assertTrue($res); $data =& $rd->data(); $this->assertEquals(count($data), 3); $this->assertEquals($data[10]['fname'], 'John'); $this->assertTrue(!isset($data[10]['photo'])); $this->assertTrue(isset($data[10]['__photo_length'])); }
function &df_get_records($table, $query = null, $start = null, $limit = null, $preview = true) { import('Dataface/QueryTool.php'); $app = Dataface_Application::getInstance(); if ($query === null and $start === null and $limit === null) { $queryTool = Dataface_QueryTool::loadResult($table); } else { if ($query === null or !$query) { $query = array(); } if ($start !== null) { $query['-skip'] = $start; } if ($limit !== null) { $query['-limit'] = $limit; } $queryTool = new Dataface_QueryTool($table, null, $query); } $queryTool->loadSet('', false, false, $preview); $it = $queryTool->iterator(); return $it; }
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; }