Public Member Functions | |
__construct (Connection $conn) | |
Creates a new IdGenerator class, saves passed connection for use later by getId() method. | |
isBeforeInsert () | |
isAfterInsert () | |
getIdMethod () | |
getId ($seqname=null) | |
create ($seqname) | |
Creates the sequence emulation table. | |
drop ($seqname, $ignoreerrs=false) | |
Drops the sequence emulation table. | |
Private Attributes | |
$conn | |
Connection object that instantiated this class. |
Definition at line 16 of file ODBCIdGenerator.php.
ODBCIdGenerator::__construct | ( | Connection $ | conn | ) |
Creates a new IdGenerator class, saves passed connection for use later by getId() method.
Connection | $conn |
Definition at line 26 of file ODBCIdGenerator.php.
00027 { 00028 $this->conn = $conn; 00029 }
ODBCIdGenerator::create | ( | $ | seqname | ) |
Creates the sequence emulation table.
Definition at line 100 of file ODBCIdGenerator.php.
Referenced by getId().
00101 { 00102 $this->conn->executeUpdate("CREATE TABLE $seqname ( id numeric(19,0) NOT NULL )"); 00103 $this->conn->executeUpdate("INSERT INTO $seqname ( id ) VALUES ( 0 )"); 00104 }
ODBCIdGenerator::drop | ( | $ | seqname, | |
$ | ignoreerrs = false | |||
) |
Drops the sequence emulation table.
Definition at line 109 of file ODBCIdGenerator.php.
Referenced by getId().
00110 { 00111 try { 00112 $this->conn->executeUpdate("DROP TABLE $seqname"); 00113 } catch (Exception $e) { 00114 if (!$ignoreerrs) throw $e; 00115 } 00116 }
ODBCIdGenerator::getId | ( | $ | seqname = null |
) |
Implements IdGenerator.
Definition at line 58 of file ODBCIdGenerator.php.
References create(), drop(), and ResultSet::FETCHMODE_NUM.
00059 { 00060 if ($seqname === null) 00061 throw new SQLException('You must specify the sequence name when calling getId() method.'); 00062 00063 $triedcreate = false; 00064 00065 while (1) 00066 { 00067 try 00068 { 00069 $n = $this->conn->executeUpdate("UPDATE $seqname SET id = id + 1", ResultSet::FETCHMODE_NUM); 00070 00071 if ($n == 0) 00072 throw new SQLException('Failed to update IdGenerator id', $this->conn->nativeError()); 00073 00074 $rs = $this->conn->executeQuery("SELECT id FROM $seqname", ResultSet::FETCHMODE_NUM); 00075 } 00076 catch (SQLException $e) 00077 { 00078 //$odbcerr = odbc_error($this->conn->getResource()); 00079 00080 if ($triedcreate)// || ($odbcerr != 'S0000' && $odbcerr != 'S0002')) 00081 throw $e; 00082 00083 $this->drop($seqname, true); 00084 $this->create($seqname); 00085 $triedcreate = true; 00086 continue; 00087 } 00088 00089 break; 00090 } 00091 00092 $rs->first(); 00093 00094 return $rs->getInt(1); 00095 }
ODBCIdGenerator::getIdMethod | ( | ) |
Implements IdGenerator.
Definition at line 50 of file ODBCIdGenerator.php.
ODBCIdGenerator::isAfterInsert | ( | ) |
Implements IdGenerator.
Definition at line 42 of file ODBCIdGenerator.php.
ODBCIdGenerator::isBeforeInsert | ( | ) |
Implements IdGenerator.
Definition at line 34 of file ODBCIdGenerator.php.
ODBCIdGenerator::$conn [private] |