Changeset 174
- Timestamp:
- 01/30/07 00:46:58 (2 years ago)
- Files:
-
- trunk/src/main/php/net/stubbles/rdbms/pdo/stubDatabasePDOConnection.php (modified) (6 diffs)
- trunk/src/main/php/net/stubbles/rdbms/rdbms.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/rdbms/stubDatabaseConnectionData.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/rdbms/stubDatabaseConnectionPool.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/rdbms (added)
- trunk/src/test/php/net/stubbles/rdbms/RDBMSTestSuite.php (added)
- trunk/src/test/php/net/stubbles/rdbms/pdo (added)
- trunk/src/test/php/net/stubbles/rdbms/pdo/stubDatabasePDOConnectionTestCase.php (added)
- trunk/src/test/php/net/stubbles/rdbms/stubDatabaseConnectionDataTestCase.php (added)
- trunk/src/test/php/net/stubbles/rdbms/stubDatabaseConnectionPoolTestCase.php (added)
- trunk/src/test/run.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/rdbms/pdo/stubDatabasePDOConnection.php
r173 r174 30 30 * @var PDO 31 31 */ 32 protected $pdo = null;32 protected $pdo = null; 33 33 34 34 /** … … 175 175 176 176 try { 177 $pdoStatement = $this->pdo->prepare($statement, $driverOptions); 178 } catch (PDOException $pdoe) { 179 throw new stubDatabaseException($pdoe->getMessage(), $pdoe); 180 } 181 182 return new stubDatabasePDOStatement($pdoStatement); 177 $statement = new stubDatabasePDOStatement($this->pdo->prepare($statement, $driverOptions)); 178 return $statement; 179 } catch (PDOException $pdoe) { 180 throw new stubDatabaseException($pdoe->getMessage(), $pdoe); 181 } 183 182 } 184 183 … … 186 185 * executes a SQL statement 187 186 * 187 * The driver options can be: 188 * <code> 189 * fetchMode => one of the PDO::FETCH_* constants 190 * colNo => if fetchMode == PDO::FETCH_COLUMN this denotes the column number to fetch 191 * object => if fetchMode == PDO::FETCH_INTO this denotes the object to fetch the data into 192 * classname => if fetchMode == PDO::FETCH_CLASS this denotes the class to create and fetch the data into 193 * ctorargs => (optional) if fetchMode == PDO::FETCH_CLASS this denotes the list of arguments for the constructor of the class to create and fetch the data into 194 * </code> 195 * 188 196 * @param string $sql the sql query to use 189 * @param array $driverOptions optional one or more driver specific options for the call to query()197 * @param array $driverOptions optional how to fetch the data 190 198 * @return stubDatabasePDOStatement 191 199 * @throws stubDatabaseException 192 200 * @see http://php.net/pdo-query 201 * @see http://php.net/pdostatement-setfetchmode for the details on the fetch mode options 193 202 */ 194 203 public function query($sql, array $driverOptions = array()) … … 199 208 200 209 try { 201 $pdoStatement = $this->pdo->query($sql, $driverOptions['fetchMode'], $driverOptions['type'], $driverOptions['constructArgs']); 202 } catch (PDOException $pdoe) { 203 throw new stubDatabaseException($pdoe->getMessage(), $pdoe); 204 } 205 206 return new stubDatabasePDOStatement($pdoStatement); 210 if (isset($driverOptions['fetchMode']) == true) { 211 switch ($driverOptions['fetchMode']) { 212 case PDO::FETCH_COLUMN: 213 if (isset($driverOptions['colNo']) == false) { 214 throw new stubDatabaseException('Fetch mode COLUMN requires driver option ŽcolNoŽ.'); 215 } 216 217 $pdoStatement = $this->pdo->query($sql, $driverOptions['fetchMode'], $driverOptions['colNo']); 218 break; 219 case PDO::FETCH_INTO: 220 if (isset($driverOptions['object']) == false) { 221 throw new stubDatabaseException('Fetch mode INTO requires driver option ŽobjectŽ.'); 222 } 223 224 $pdoStatement = $this->pdo->query($sql, $driverOptions['fetchMode'], $driverOptions['object']); 225 break; 226 case PDO::FETCH_CLASS: 227 if (isset($driverOptions['classname']) == false) { 228 throw new stubDatabaseException('Fetch mode CLASS requires driver option ŽclassnameŽ.'); 229 } 230 231 if (isset($driverOptions['ctorargs']) == false) { 232 $driverOptions['ctorargs'] = array(); 233 } 234 235 $pdoStatement = $this->pdo->query($sql, $driverOptions['fetchMode'], $driverOptions['classname'], $driverOptions['ctorargs']); 236 break; 237 default: 238 $pdoStatement = $this->pdo->query($sql, $driverOptions['fetchMode']); 239 } 240 } else { 241 $pdoStatement = $this->pdo->query($sql); 242 } 243 } catch (PDOException $pdoe) { 244 throw new stubDatabaseException($pdoe->getMessage(), $pdoe); 245 } 246 247 $statement = new stubDatabasePDOStatement($pdoStatement); 248 return $statement; 207 249 } 208 250 … … 222 264 223 265 try { 224 $effectedRows = $this->pdo->exec($statement); 225 } catch (PDOException $pdoe) { 226 throw new stubDatabaseException($pdoe->getMessage(), $pdoe); 227 } 228 229 return $effectedRows; 266 return $this->pdo->exec($statement); 267 } catch (PDOException $pdoe) { 268 throw new stubDatabaseException($pdoe->getMessage(), $pdoe); 269 } 230 270 } 231 271 … … 244 284 245 285 try { 246 $lastInsertId = $this->pdo->lastInsertId($name); 247 } catch (PDOException $pdoe) { 248 throw new stubDatabaseException($pdoe->getMessage(), $pdoe); 249 } 250 251 return $lastInsertId; 286 return $this->pdo->lastInsertId($name); 287 } catch (PDOException $pdoe) { 288 throw new stubDatabaseException($pdoe->getMessage(), $pdoe); 289 } 252 290 } 253 291 } trunk/src/main/php/net/stubbles/rdbms/rdbms.php
r170 r174 9 9 stubClassLoader::load('net.stubbles.rdbms.stubDatabaseException', 10 10 'net.stubbles.rdbms.stubDatabaseStatement', 11 'net.stubbles.rdbms.stubDatabaseConnectionData', 11 12 'net.stubbles.rdbms.stubDatabaseConnection', 12 13 'net.stubbles.rdbms.stubDatabaseConnectionPool' trunk/src/main/php/net/stubbles/rdbms/stubDatabaseConnectionData.php
r173 r174 18 18 * id of the default connection 19 19 */ 20 const ID_DEFAULT = '__default';20 const ID_DEFAULT = '__default'; 21 21 /** 22 22 * id to use for the connection … … 59 59 /** 60 60 * set the id to use for the connection 61 * 62 * Warning: two instances will be the same if they have the same id, 63 * regardless whether the concrete connection data is differant or not. 64 * You should never use the same id for differant connection datasets. 61 65 * 62 66 * @param string $id … … 79 83 /** 80 84 * checks whether a value is equal to the class 85 * 86 * Warning: two instances will be the same if they have the same id, 87 * regardless whether the concrete connection data is differant or not. 88 * You should never use the same id for differant connection datasets. 81 89 * 82 90 * @param mixed $compare trunk/src/main/php/net/stubbles/rdbms/stubDatabaseConnectionPool.php
r173 r174 46 46 { 47 47 if (isset(self::$connections[$id]) == false) { 48 if (isset(self::$ dsns[$id]) == false) {48 if (isset(self::$connectionData[$id]) == false) { 49 49 throw new stubDatabaseException('No connection and no dsn known for connection associated with id ' . $id); 50 50 } … … 57 57 $connection = new $nqClassName(self::$connectionData[$id]); 58 58 if (($connection instanceof stubDatabaseConnection) == false) { 59 throw new stubDatabaseException(self::$connectionData[$id] ['class'] . ' is not an instance ofstubDatabaseConnection.');59 throw new stubDatabaseException(self::$connectionData[$id]->getConnectionClassName() . ' is not an instance of net.stubbles.rdbms.stubDatabaseConnection.'); 60 60 } 61 61 … … 103 103 104 104 /** 105 * removes the connection data with the given id 106 * 107 * @param string $id optional id of the connection data to remove 108 */ 109 public static function removeConnectionData($id = stubDatabaseConnectionData::ID_DEFAULT) 110 { 111 if (isset(self::$connectionData[$id]) == true) { 112 self::$connectionData[$id] = null; 113 } 114 } 115 116 /** 105 117 * closes the connection with the given id 106 118 * trunk/src/test/run.php
r154 r174 32 32 $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/ioc/IOCTestSuite.php'); 33 33 $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/ipo/IPOTestSuite.php'); 34 $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/rdbms/RDBMSTestSuite.php'); 34 35 $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/reflection/ReflectionTestSuite.php'); 35 36 $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/util/UtilTestSuite.php');
