* added a getDefinition for columns and indexes - I am not very sure it's a very...
[vsc.git] / _res / _libs / models / foo / footdoa.class.php
blob4752135a6c9aa80b19a13d4b7d30500903c49c42
1 <?php
2 /**
3 * the query compiler/executer object
4 * @package ts_models
5 * @author Marius Orcsik <marius@habarnam.ro>
6 * @version 0.0.1
7 */
8 abstract class fooTdoA {
9 /**
10 * @var fooSqlDriverA
12 private $oConnection;
14 /**
15 * @param fooSqlDriverA $oConnection
16 * @return void
18 public function setConnection (fooSqlDriverA $oConnection) {
19 $this->oConnection = $oConnection;
22 /**
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;
31 /**
32 * Outputs the SQL necessary for creating the table
33 * @return string
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() ;
42 $sRet .= ', ' . "\n";
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);
55 $sRet.= "\n" . ' ) ';
57 if ($this->oConnection->getType() == 'mysql') {
58 $sRet.= ' ENGINE ' . $this->getConnection()->getEngine();
61 return $sRet;
64 static public function isValidConnection ($oConnection) {
65 return sqlFactory::validType ($oConnection->getType());