예제 #1
0
 /**
  * Returns the integer value of the generated identifier for the new object.
  * Called right after execution of the insert query.
  * Dispatches to {@link ezcPersistentNativeGenerator} for MySQL.
  *
  * @param ezcPersistentObjectDefinition $def
  * @param ezcDbHandler $db
  * @return int
  */
 public function postSave(ezcPersistentObjectDefinition $def, ezcDbHandler $db)
 {
     if ($db->getName() == "mysql" || $db->getName() == "sqlite") {
         $native = new ezcPersistentNativeGenerator();
         return $native->postSave($def, $db);
     }
     $id = null;
     if (array_key_exists('sequence', $def->idProperty->generator->params) && $def->idProperty->generator->params['sequence'] !== null) {
         switch ($db->getName()) {
             case "oracle":
                 $idRes = $db->query("SELECT " . $db->quoteIdentifier($def->idProperty->generator->params['sequence']) . ".CURRVAL AS id FROM " . $db->quoteIdentifier($def->table))->fetch();
                 $id = (int) $idRes["id"];
                 break;
             default:
                 $id = (int) $db->lastInsertId($db->quoteIdentifier($def->idProperty->generator->params['sequence']));
                 break;
         }
     } else {
         $id = (int) $db->lastInsertId();
     }
     // check that the value was in fact successfully received.
     if ($db->errorCode() != 0) {
         return null;
     }
     return $id;
 }
 /**
  * Returns next value for "id" column.
  *
  * @return mixed
  */
 public function getNextId()
 {
     $sequence = $this->dbHandler->getSequenceName('ezurlalias_ml_incr', 'id');
     /** @var $query \ezcQueryInsert */
     $query = $this->dbHandler->createInsertQuery();
     $query->insertInto($this->dbHandler->quoteTable("ezurlalias_ml_incr"));
     // ezcDatabase does not abstract the "auto increment id"
     // INSERT INTO ezurlalias_ml_incr VALUES(DEFAULT) is not an option due
     // to this mysql bug: http://bugs.mysql.com/bug.php?id=42270
     // as a result we are forced to check which database is currently used
     // to generate the correct SQL query
     // see https://jira.ez.no/browse/EZP-20652
     if ($this->dbHandler->getName() === 'pgsql') {
         $query->set($this->dbHandler->quoteColumn("id"), "nextval('{$sequence}')");
     } else {
         $query->set($this->dbHandler->quoteColumn("id"), $query->bindValue(null, null, \PDO::PARAM_NULL));
     }
     $query->prepare()->execute();
     return $this->dbHandler->lastInsertId($sequence);
 }
예제 #3
0
 /**
  * Creates the tables defined in the schema into the database specified through $db.
  *
  * @throws ezcDbSchemaInvalidWriterClassException if the handler associated
  *         with the $format is not a database schema writer.
  *
  * @param ezcDbHandler $db
  */
 public function writeToDb(ezcDbHandler $db)
 {
     self::initOptions();
     $className = ezcDbSchemaHandlerManager::getWriterByFormat($db->getName());
     $writer = new $className();
     self::checkSchemaWriter($writer, self::DATABASE);
     $writer->saveToDb($db, $this);
 }
예제 #4
0
 /**
  * Upgrades the database $db with the differences.
  *
  * @throws ezcDbSchemaInvalidWriterClassException if the handler associated
  *         with the $format is not a database schema writer.
  *
  * @param ezcDbHandler $db
  */
 public function applyToDb(ezcDbHandler $db)
 {
     $className = ezcDbSchemaHandlerManager::getDiffWriterByFormat($db->getName());
     $writer = new $className();
     self::checkSchemaDiffWriter($writer, ezcDbSchema::DATABASE);
     $writer->applyDiffToDb($db, $this);
 }