. */ require_once 'creole/IdGenerator.php'; /** * PostgreSQL IdGenerator implemenation. * * @author Hans Lellelid * @version $Revision: 1.5 $ * @package creole.drivers.pgsql */ class PgSQLIdGenerator implements IdGenerator { /** Connection object that instantiated this class */ private $conn; /** * Creates a new IdGenerator class, saves passed connection for use * later by getId() method. * @param Connection $conn */ public function __construct(Connection $conn) { $this->conn = $conn; } /** * @see IdGenerator::isBeforeInsert() */ public function isBeforeInsert() { return true; } /** * @see IdGenerator::isAfterInsert() */ public function isAfterInsert() { return false; } /** * @see IdGenerator::getIdMethod() */ public function getIdMethod() { return self::SEQUENCE; } /** * @see IdGenerator::getId() */ public function getId($name = null) { if ($name === null) { throw new SQLException("You must specify the sequence name when calling getId() method."); } $rs = $this->conn->executeQuery("SELECT nextval('" . pg_escape_string ( $name ) . "')", ResultSet::FETCHMODE_NUM); $rs->next(); return $rs->getInt(1); } }