blob: d9ec19d00468a0bb2986db6c6bb7a598a6cd2d6e [file] [log] [blame]
<?php
/**
* File containing the ezcPersistentNativeGenerator class
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* @package PersistentObject
* @version //autogen//
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
*/
/**
* Generates IDs based on the PDO::lastInsertId method.
*
* It is recommended to use auto_increment id columns for databases supporting
* it. This includes MySQL and SQLite. Other databases need to create a sequence
* per table.
*
* auto_increment databases:
* <code>
* CREATE TABLE test
* ( id integer unsigned not null auto_increment, PRIMARY KEY (id ));
* </code>
*
* @package PersistentObject
* @version //autogen//
*/
class ezcPersistentNativeGenerator extends ezcPersistentIdentifierGenerator
{
/**
* No functionality, since database handles ID generation automatically.
*
* @param ezcPersistentObjectDefinition $def
* @param ezcDbHandler $db
* @param ezcQueryInsert $q
* @return void
*/
public function preSave( ezcPersistentObjectDefinition $def, ezcDbHandler $db, ezcQueryInsert $q )
{
}
/**
* Returns the integer value of the generated identifier for the new object.
* Called right after execution of the insert query.
*
* @param ezcPersistentObjectDefinition $def
* @param ezcDbHandler $db
* @return int
*/
public function postSave( ezcPersistentObjectDefinition $def, ezcDbHandler $db )
{
$id = (int)$db->lastInsertId();
// check that the value was in fact successfully received.
if ( $db->errorCode() != 0 )
{
return null;
}
return $id;
}
}
?>