/**
  * Override {@link epDbPort::createTable()}
  * 
  * Generate SQL code to create table
  * 
  * @param epClassMap $cm
  * @param string $indent
  * @param epDb $db
  * @return string|array (of strings)
  */
 public function createTable($cm, $db, $indent = '  ')
 {
     // start create table
     $sql = "CREATE TABLE " . $db->quoteId($cm->getTable()) . " (";
     // the oid field
     $fstr = $this->_defineField($db->quoteId($cm->getOidColumn()), 'INTEGER', '12', false, true);
     $sql .= $fstr . ",";
     // write sql for each field
     foreach ($cm->getAllFields() as $fname => $fm) {
         if ($fm->isPrimitive()) {
             // get the field definition
             $fstr = $this->_defineField($db->quoteId($fm->getColumnName()), $fm->getType(), $fm->getTypeParams(), $fm->getDefaultValue(), false);
             $sql .= $fstr . ",";
         }
     }
     // remove the last ','
     $sql = substr($sql, 0, strlen($sql) - 1);
     // end of table creation
     $sql .= ");";
     return $sql;
 }
 /**
  * Generate SQL code to create table
  * 
  * Sometimes extra procedure may be needed for some fields to work. 
  * For example, some database does not have a direct auto-incremental 
  * keyword and, to make it work, you need extra procedure after 
  * creating the table. Here is an example, for a table column in 
  * an Oracle database to be auto-incremental, we need to insert 
  * a sequence and a trigger (See this link for more info 
  * {@link http://webxadmin.free.fr/article.php?i=134}). If this is 
  * the case the subclass should override this method and return both
  * "create table" statement and the extra.
  * 
  * @param epClassMap $cm
  * @param epDb $db
  * @param string $indent
  * @return string|array (of strings)
  */
 public function createTable($cm, $db, $indent = '  ')
 {
     // start create table
     $sql = "CREATE TABLE " . $db->quoteId($cm->getTable()) . " (\n";
     // the oid field
     $fstr = $this->_defineField($db->quoteId($cm->getOidColumn()), 'integer', '12', false, true);
     $sql .= $indent . $fstr . ",\n";
     // write sql for each field
     foreach ($cm->getAllFields() as $fname => $fm) {
         if ($fm->isPrimitive()) {
             // get the field definition
             $fstr = $this->_defineField($db->quoteId($fm->getColumnName()), $fm->getType(), $fm->getTypeParams(), $fm->getDefaultValue(), false);
             $sql .= $indent . $fstr . ",\n";
         }
     }
     // write primary key
     $sql .= $indent . "PRIMARY KEY (" . $db->quoteId($cm->getOidColumn()) . ")\n";
     // end of table creation
     $sql .= ");\n";
     return $sql;
 }
 /**
  * Override {@link epDbPort::createTable()}
  *
  * Generate SQL code to create table
  *
  * @param epClassMap $cm
  * @param string $indent
  * @param epDb $db
  * @return string|array (of strings)
  */
 public function createTable($cm, $db, $indent = '  ')
 {
     // start create table
     $sql = "CREATE TABLE \"" . $cm->getTable() . "\" (";
     $sql = $sql . "CONSTRAINT " . $cm->getTable() . "_" . $cm->getOidColumn() . " PRIMARY KEY (" . $cm->getOidColumn() . "),";
     // the oid field
     $fstr = $this->_defineField($cm->getOidColumn(), 'Integer', '', false, true);
     $sql .= $fstr . ",";
     // write sql for each field
     foreach ($cm->getAllFields() as $fname => $fm) {
         if ($fm->isPrimitive()) {
             // get the field definition
             $fstr = $this->_defineField($db->quoteId($fm->getColumnName()), $fm->getType(), $fm->getTypeParams(), $fm->getDefaultValue(), false);
             $sql .= $fstr . ",";
         }
     }
     // remove the last ','
     $sql = substr($sql, 0, strlen($sql) - 1);
     // end of table creation
     // WITH OIDS - see http://www.ezpdo.net/forum/viewtopic.php?pid=750#p750
     $sql .= ") WITH OIDS;";
     return $sql;
 }
Beispiel #4
0
 /**
  * Collect and cache all vars for the object
  * @return void
  * @access protected
  */
 protected function _collectVars()
 {
     // collect vars in objects
     $this->ep_cached_vars = array_keys(get_object_vars($this->ep_object));
     // add private/protected vars in case missed out
     if ($this->ep_cm) {
         // has __get() or __set() in class?
         $has__get = in_array('__get', $this->ep_cached_methods);
         $has__set = in_array('__set', $this->ep_cached_methods);
         // get all vars from class map
         $vars = array_keys($this->ep_cm->getAllFields());
         // go through all vars and collect accessible non-public vars
         // 'accessible' means a var has both public getter and setter
         foreach ($vars as $var) {
             // skip if already collected
             if (in_array($var, $this->ep_cached_vars)) {
                 continue;
             }
             // does it have public g/setter?
             $hasGetter = $has__get || in_array('get' . ucfirst($var), $this->ep_cached_methods);
             $hasSetter = $has__set || in_array('set' . ucfirst($var), $this->ep_cached_methods);
             // collect it if publically accessible
             if ($hasGetter && $hasSetter) {
                 $this->ep_cached_vars[] = $var;
             }
         }
     }
 }
 /**
  * Converts the last record set into epObject object(s) with class map
  * @param epClassMap $cm the class map for the conversion
  * @param array (of integers) object ids to be excluded
  * @return false|array (of epObject)
  * @throws epExceptionDbObject
  */
 protected function _rs2obj($cm, $oids_ex = null)
 {
     // !!!important!!! with a large db, the list of oid to be excluded
     // $oids_ex can grown really large and can significantly slow down
     // queries. so it is suppressed in the select statement and moved
     // to this method to process.
     // get epManager instance and cache it
     if (!$this->ep_m) {
         $this->ep_m =& epManager::instance();
     }
     // get the class name
     $class = $cm->getName();
     // get all mapped vars
     if (!($fms = $cm->getAllFields())) {
         return self::$false;
     }
     // reset counter and return value
     $ret = array();
     // go through reach record
     $okay = $this->db->rsRestart();
     while ($okay) {
         // get oid column
         $oid = $this->db->rsGetCol($cn = $cm->getOidColumn(), $class . '.' . $cn);
         // exclude it?
         if ($oids_ex && in_array($oid, $oids_ex)) {
             // next row
             $okay = $this->db->rsNext();
             // exclude it
             continue;
         }
         // call epManager to create an instance (false: no caching; false: no event dispatching)
         if (!($o =& $this->ep_m->_create($class, false, false))) {
             // next row
             $okay = $this->db->rsNext();
             continue;
         }
         // go through each field
         foreach ($fms as $fname => $fm) {
             // skip non-primivite field
             if (!$fm->isPrimitive()) {
                 continue;
             }
             // get var value and set to object
             $val = $this->db->rsGetCol($cn = $fm->getColumnName(), $class . '.' . $cn);
             // set value to var (true: no dirty flag change)
             $o->epSet($fm->getName(), $this->_castType($val, $fm->getType()), true);
         }
         // set oid
         $o->epSetObjectId($oid);
         // collect return result
         $ret[] = $o;
         // next row
         $okay = $this->db->rsNext();
     }
     return $ret;
 }