/** * get autoincrement PK field */ protected function getAutoIncrementPKField($using = null) { if ($using === null) { $using = $this->_dataParser->getProperties(); } $tb = $this->_dataParser->getTables(); $tb = $tb[$this->_dataParser->getPrimaryTable()]['realname']; foreach ($using as $id => $field) { if (!$field->isPK) { continue; } if ($field->autoIncrement) { return $field; } } return null; }
protected function import($xml, $tools) { if (isset($xml['import'])) { $import = (string) $xml['import']; jApp::pushCurrentModule($this->selector->module); // Keep the same driver as current used $importSel = new jSelectorDaoDb($import, $this->selector->driver, $this->selector->dbType); jApp::popCurrentModule(); $doc = new DOMDocument(); if (!$doc->load($importSel->getPath())) { throw new jException('jelix~daoxml.file.unknown', $importSel->getPath()); } $parser = new jDaoParser($importSel); $parser->parse(simplexml_import_dom($doc), $tools); $this->_properties = $parser->getProperties(); $this->_tables = $parser->getTables(); $this->_primaryTable = $parser->getPrimaryTable(); $this->_methods = $parser->getMethods(); $this->_ojoins = $parser->getOuterJoins(); $this->_ijoins = $parser->getInnerJoins(); $this->_eventList = $parser->getEvents(); $this->_userRecord = $parser->getUserRecord(); $this->_importedDao = $parser->getImportedDao(); $this->hasOnlyPrimaryKeys = $parser->hasOnlyPrimaryKeys; if ($this->_importedDao) { $this->_importedDao[] = $importSel; } else { $this->_importedDao = array($importSel); } } }
function testBuildConditions() { $doc = '<?xml version="1.0" encoding="UTF-8"?> <dao xmlns="http://jelix.org/ns/dao/1.0"> <datasources> <primarytable name="grp" realname="jacl_group" primarykey="id_aclgrp" /> </datasources> <record> <property name="id_aclgrp" fieldname="id_aclgrp" datatype="autoincrement" required="yes"/> <property name="parent_id" required="false" datatype="int" /> <property name="name" fieldname="name" datatype="string" required="yes"/> <property name="grouptype" fieldname="grouptype" datatype="int" required="yes"/> <property name="ownerlogin" fieldname="ownerlogin" datatype="string" /> </record> <factory> <method name="method1" type="select"> <conditions> <eq property="grouptype" value="1" /> </conditions> </method> <method name="method2" type="select" groupby="id_aclgrp,parent_id,name"> <conditions> <neq property="grouptype" value="2" /> </conditions> <order> <orderitem property="name" way="asc" /> </order> </method> <method name="method3" type="select"> <order> <orderitem property="name" way="asc" /> </order> </method> <method name="method4" type="select" groupby="id_aclgrp,parent_id,name"> <order> <orderitem property="name" way="asc" /> </order> </method> </factory> </dao>'; $parser = new jDaoParser($this->_selector); $parser->parse(simplexml_load_string($doc), $this->_tools); $generator = new testMysqlDaoGenerator($this->_selector, $this->_tools, $parser); $methods = $parser->getMethods(); $this->assertTrue($methods['method1']->getConditions() != null); $sql = $generator->BuildConditions2($methods['method1']->getConditions(), $parser->getProperties(), $methods['method1']->getParameters(), false, $methods['method1']->getGroupBy()); $this->assertEqualOrDiff(' `grouptype` = 1', $sql); $this->assertTrue($methods['method2']->getConditions() != null); $sql = $generator->BuildConditions2($methods['method2']->getConditions(), $parser->getProperties(), $methods['method2']->getParameters(), false, $methods['method2']->getGroupBy()); $this->assertEqualOrDiff(' `grouptype` <> 2 GROUP BY `id_aclgrp`, `parent_id`, `name` ORDER BY `name` asc', $sql); $this->assertTrue($methods['method3']->getConditions() !== null); $sql = $generator->BuildConditions2($methods['method3']->getConditions(), $parser->getProperties(), $methods['method3']->getParameters(), false, $methods['method3']->getGroupBy()); $this->assertEqualOrDiff(' 1=1 ORDER BY `name` asc', $sql); $this->assertTrue($methods['method4']->getConditions() !== null); $sql = $generator->BuildConditions2($methods['method4']->getConditions(), $parser->getProperties(), $methods['method4']->getParameters(), false, $methods['method4']->getGroupBy()); $this->assertEqualOrDiff(' 1=1 GROUP BY `id_aclgrp`, `parent_id`, `name` ORDER BY `name` asc', $sql); $sql = $generator->BuildConditions2($methods['method1']->getConditions(), $parser->getProperties(), $methods['method1']->getParameters(), true, $methods['method1']->getGroupBy()); $this->assertEqualOrDiff(' `grp`.`grouptype` = 1', $sql); $sql = $generator->BuildConditions2($methods['method2']->getConditions(), $parser->getProperties(), $methods['method2']->getParameters(), true, $methods['method2']->getGroupBy()); $this->assertEqualOrDiff(' `grp`.`grouptype` <> 2 GROUP BY `grp`.`id_aclgrp`, `grp`.`parent_id`, `grp`.`name` ORDER BY `grp`.`name` asc', $sql); $sql = $generator->BuildConditions2($methods['method3']->getConditions(), $parser->getProperties(), $methods['method3']->getParameters(), true, $methods['method3']->getGroupBy()); $this->assertEqualOrDiff(' 1=1 ORDER BY `grp`.`name` asc', $sql); $sql = $generator->BuildConditions2($methods['method4']->getConditions(), $parser->getProperties(), $methods['method4']->getParameters(), true, $methods['method4']->getGroupBy()); $this->assertEqualOrDiff(' 1=1 GROUP BY `grp`.`id_aclgrp`, `grp`.`parent_id`, `grp`.`name` ORDER BY `grp`.`name` asc', $sql); }