コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
 /**
  * Converts the last record set into uoids
  * @param epClassMap $cm the class map for the conversion
  * @param array (of integers) object ids to be excluded
  * @return false|array (of uoids)
  * @throws epExceptionDbObject
  */
 protected function _rs2uoid($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 the class name
     $class = $cm->getName();
     // 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;
         }
         // get class_b
         $class_b = $this->db->rsGetCol('class_b', $class . '.' . 'class_b');
         // get oid_b
         $oid_b = $this->db->rsGetCol('oid_b', $class . '.' . 'oid_b');
         // collect return result
         $ret[] = $class_b . ':' . $oid_b;
         // next row
         $okay = $this->db->rsNext();
     }
     return $ret;
 }
コード例 #5
0
 /**
  * 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, $ex = null)
 {
     // !!!important!!! with a large db, the list of oid to be excluded
     // $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 ($ex && in_array($oid, $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;
 }