3 * the query compiler/executer object
5 * @author Marius Orcsik <marius@habarnam.ro>
8 abstract class fooTdoA
{
15 * @param fooSqlDriverA $oConnection
18 public function setConnection (fooSqlDriverA
$oConnection) {
19 $this->oConnection
= $oConnection;
23 * @return fooSqlDriverA
25 public function getConnection () {
26 if (!self
::isValidConnection($this->oConnection
))
27 throw new fooInvalidTypeException ('Could not establish a valid DB connection - current resource type [' . get_class ($this->oConnection
) . ']');
28 return $this->oConnection
;
32 * Outputs the SQL necessary for creating the table
35 public function outputCreateSQL (fooEntityA
$oInc) {
36 $sRet = $this->getConnection()->_CREATE ($oInc->getName()) . "\n";
37 $sRet .= ' ( ' . "\n";
39 /* @var $oColumn fooFieldA */
40 foreach ($oInc->getMembers () as $oColumn) {
41 $sRet .= "\t" . $oColumn->getName() . ' ' . $oColumn->getDefinition() ;
45 $aIndexes = $oInc->getIndexes(true);
46 if (is_array ($aIndexes)) {
47 foreach ($aIndexes as $oIndex) {
48 // this needs to be replaced with connection functionality : something like getConstraint (type, columns)
49 $sRet .= "\t" . $oIndex->getDefinition() . ", \n"; //getType() . ' KEY ' . $oIndex->getName() . ' (' . $oIndex->getIndexComponents(). '), ' . "\n";
53 $sRet = substr( $sRet, 0, -3);
57 if ($this->oConnection
->getType() == 'mysql') {
58 $sRet.= ' ENGINE ' . $this->getConnection()->getEngine();
64 static public function isValidConnection ($oConnection) {
65 return sqlFactory
::validType ($oConnection->getType());