/** * Get a database manager * @returns pdoMap_Database_Reques_Adapters_IBuilder */ public function manager($database) { if (!isset($this->managers[$database])) { $type = pdoMap::database()->getType($database); $manager = 'pdoMap_Database_Request_Adapters_' . $type . '_Builder'; $this->register($database, new $manager($database)); } return $this->managers[$database]; }
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 . ']'; } }
public function Count() { $l = $this->scope->args['limit']; $f = $this->scope->args['fields']; $this->scope->args['fields'] = array('COUNT(*) AS NB'); $this->scope->args['limit'] = array(); $ret = pdoMap::database()->Request($this->scope->database, $this->scope->Request()); $ret = pdoMap::database()->Fetch($ret); $this->scope->args['fields'] = $f; $this->scope->args['limit'] = $l; return $ret['NB']; }
public function Run() { if ($this->mode == 'select') { return pdoMap::database()->RequestArray($this->database, $this->Request(), $this->table[0]); } else { if ($this->mode == 'insert') { $ret = pdoMap::database()->Request($this->database, $this->Request()); if ($ret) { return pdoMap::database()->getPdo($this->database)->lastInsertId(); } else { return false; } } else { return pdoMap::database()->Request($this->database, $this->Request()); } } }
/** * Registering database connections */ public function __wakeup() { foreach ($this->data['connections'] as $key => $cnx) { pdoMap::database()->Register($cnx['dns'], $cnx['user'], $cnx['pwd'], $cnx['prefix'], $key); } }
/** * Get to the next item */ public function next() { $this->index++; if (!isset($this->buffer[$this->index])) { $this->buffer[$this->index] = pdoMap::database()->Fetch($this->ptr); } if ($this->type && $this->buffer[$this->index]) { $this->current = pdoMap::get($this->type)->Create($this->buffer[$this->index]); } else { $this->current = $this->buffer[$this->index]; } }
public function Create($drop = false) { $name = pdoMap::database()->getName($this->database); if ($drop) { $this->Drop(); } pdoMap::database()->Change(''); pdoMap::database()->Request($this->database, sprintf($this->sqlCreateSchema, $this->escapeEntity($name), $this->character_set, $this->collate)); pdoMap::database()->Change($name); }
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); }
/** * Get the database manager */ public static function database() { if (!self::$database) { self::$database = new pdoMap_Database_Manager(); } return self::$database; }