Ejemplo n.º 1
0
 public static function escapeEntity($name, $table = null)
 {
     if ($table) {
         $db = pdoMap::structure($table)->db;
         $table = pdoMap::database()->getPrefix($db) . pdoMap::structure($table)->name;
         return '[' . $table . '].[' . $name . ']';
     } else {
         return '[' . $name . ']';
     }
 }
Ejemplo n.º 2
0
 public function __construct($scope, $database, $name)
 {
     $this->scope = $scope;
     $this->scope->mode = 'select';
     $this->scope->database = $database;
     $this->scope->table[0] = $name;
     $this->scope->args = array('join' => array(), 'cond' => array(), 'fields' => array(), 'order' => array(), 'limit' => array());
     foreach (pdoMap::structure($name)->fields as $field) {
         $this->scope->args['fields'][] = $this->scope->escapeEntity($field->bind, $name) . ' AS ' . $this->scope->escapeObject($field->bind);
     }
 }
Ejemplo n.º 3
0
 /**
  * Build join tags
  */
 public function getJoin($joins)
 {
     foreach ($joins as $join) {
         if (!$join->adapter) {
             throw new Exception('Expecting to define the adapter on join !');
         }
         if (!$join->on) {
             $on = $this->getType();
         } else {
             $on = $join->on;
         }
         $field = null;
         if (!$join->field) {
             $fields = pdoMap::structure($join->adapter)->getFields();
             foreach ($fields as $f) {
                 if ($f->getOption('adapter') == $on) {
                     $field = $f->bind;
                     break;
                 }
             }
             if (!$field) {
                 throw new Exception('Join error : unable to find a foreign key for ' . $on . ' on adapter ' . $join->adapter);
             }
         } else {
             $field = $join->field;
         }
         if ($join->adapter != $this->getType()) {
             $pk = pdoMap::structure($join->adapter)->getPk()->bind;
         } else {
             $pk = $this->getPk();
         }
         $this->writeLine('->Join(\'' . $on . '\', \'' . $field . '\', \'' . $join->adapter . '\', \'' . $pk . '\')');
     }
 }
Ejemplo n.º 4
0
 /**
  * Get a typed request manager
  * @returns pdoMap_Database_Reques_Adapters_IBuilder         
  */
 public function get($type)
 {
     return $this->manager(pdoMap::structure($type)->db)->type($type);
 }
Ejemplo n.º 5
0
 /**
  * Get entity structure
  */
 public function getStructure()
 {
     return pdoMap::structure($this->type);
 }
Ejemplo n.º 6
0
 public function JoinAll()
 {
     $found = false;
     $sql = 'ALTER TABLE ' . pdoMap_Database_Request_Adapters_MySQL_Builder::escapeTable($this->name, $this->database) . "\n";
     foreach ($this->fields as $field) {
         if ($field->type == pdoMap_Mapping_Metadata_Field::FIELD_TYPE_FK) {
             $sql .= ' ADD CONSTRAINT ' . pdoMap_Database_Request_Adapters_MySQL_Builder::escapeEntity($this->name . '_' . $field->name) . ' FOREIGN KEY(';
             $sql .= pdoMap_Database_Request_Adapters_MySQL_Builder::escapeEntity($field->name);
             $sql .= ') REFERENCES ';
             $ref = pdoMap::structure($field->adapter);
             if (!$ref) {
                 throw new Exception('Could not join ' . $field->bind . ' to an undefined table ' . $field->adapter);
             }
             $sql .= pdoMap_Database_Request_Adapters_MySQL_Builder::escapeTable($ref->name, $ref->db);
             $sql .= ' (' . pdoMap_Database_Request_Adapters_MySQL_Builder::escapeEntity($ref->getPk()->name) . ')';
             $sql .= ' ON DELETE CASCADE, ' . "\n";
             $found = true;
         }
     }
     if (!$found) {
         return true;
     }
     $sql = substr($sql, 0, strlen($sql) - 3);
     return pdoMap::database()->Request($this->database, $sql);
 }
Ejemplo n.º 7
0
 public function escapeTable($name)
 {
     return pdoMap_Database_Request_Adapters_MySQL_Builder::escapeTable(pdoMap::structure($name)->name, pdoMap::structure($name)->db);
 }