Changeset 6010
- Timestamp:
- 11/14/07 11:11:46 (2 years ago)
- Files:
-
- branches/1.0/lib/vendor/creole/Creole.php (modified) (3 diffs)
- branches/1.0/lib/vendor/creole/CreoleTypes.php (modified) (2 diffs)
- branches/1.0/lib/vendor/creole/drivers/mysql/MySQLResultSet.php (modified) (1 diff)
- branches/1.0/lib/vendor/creole/drivers/mysqli/MySQLiConnection.php (modified) (8 diffs)
- branches/1.0/lib/vendor/creole/drivers/mysqli/metadata/MySQLiTableInfo.php (modified) (3 diffs)
- branches/1.0/lib/vendor/creole/drivers/oracle/OCI8Connection.php (modified) (2 diffs)
- branches/1.0/lib/vendor/creole/drivers/oracle/OCI8Types.php (modified) (2 diffs)
- branches/1.0/lib/vendor/creole/drivers/sqlite/SQLiteResultSet.php (modified) (1 diff)
- branches/1.0/lib/vendor/creole/drivers/sqlite/metadata/SQLiteTableInfo.php (modified) (4 diffs)
- branches/1.0/lib/vendor/creole/metadata/DatabaseInfo.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.0/lib/vendor/creole/Creole.php
r6007 r6010 252 252 return self::$connectionMap[$connectionMapKey][(int)$persistent] = $obj; 253 253 } 254 255 /**254 255 /** 256 256 * Parse a data source name. 257 257 * … … 269 269 * The format of the supplied DSN is in its fullest form: 270 270 * 271 * phptype://username:password@ hostspec/database271 * phptype://username:password@protocol+hostspec/database 272 272 * 273 273 * Most variations are allowed: 274 274 * 275 * phptype://username:password@protocol (hostspec:110)//usr/db_file.db275 * phptype://username:password@protocol+hostspec:110//usr/db_file.db 276 276 * phptype://username:password@hostspec/database_name 277 277 * phptype://username:password@hostspec … … 301 301 ); 302 302 303 $preg_query = "!^(([a-z0-9]+)(\(([^()]+)\))?)(://((((([^@/:]+)(:([^@/]*))?)@)?((([a-z]+)\((([^?():]+)(:([^()?]+))?)\))|((([^/?:]+)(:([^/?]+))?))))/?)?([^?]+)?(\?(.+))?)?$!i"; 304 305 $info = array(); 306 307 if (preg_match($preg_query,$dsn,$info)) { // only if it is matching 308 309 $parsed['phptype'] = @$info[2]; // Group 2 should always exist. 310 311 // Don't know what to do with Group 4: phptype(xx) should => check first if available 312 313 if (isset($info[5])) { // There is more than just the phptype 314 315 if (strlen($info[10]) > 0) { // There is a username specified 316 $parsed['username'] = @$info[10]; 317 } 318 319 if (strlen($info[12]) > 0) { // There is a password specified 320 $parsed['password'] = @$info[12]; 321 } 322 323 if (strlen($info[15]) > 0) { // There is a protocol specified: protocol(hostspec) 324 $parsed['protocol'] = @$info[15]; 325 326 if ($parsed["protocol"] === "unix") { 327 $parsed['socket'] = @$info[16]; 328 } else { 329 $parsed["hostspec"] = @$info[17]; 330 if (strlen($info[19]) > 0) { 331 $parsed["port"] = @$info[19]; 332 } 333 } 334 } elseif (strlen($info[20]) > 0) { 335 $parsed["hostspec"] = @$info[22]; 336 337 if ((isset($info[24]) && (strlen($info[24]) > 0))) { // There is a port set (not always available) 338 $parsed["port"] = @$info[24]; 339 } 340 } 341 342 if ((isset($info[25])) && (strlen($info[25]) > 0)) { // There is a database 343 $parsed["database"] = @$info[25]; 344 } 345 346 if ((isset($info[27])) && (strlen($info[27]) >0)) { // There is a query 347 $opts = explode('&', $info[27]); 348 foreach ($opts as $opt) { 349 list($key, $value) = explode('=', $opt); 350 if (!isset($parsed[$key])) { // don't allow params overwrite 351 $parsed[$key] = urldecode($value); 352 } 353 } 354 } 355 356 } 357 } 303 $info = parse_url($dsn); 304 305 if (count($info) === 1) { // if there's only one element in result, then it must be the phptype 306 $parsed['phptype'] = array_pop($info); 307 return $parsed; 308 } 309 310 // some values can be copied directly 311 $parsed['phptype'] = @$info['scheme']; 312 $parsed['username'] = @$info['user']; 313 $parsed['password'] = @$info['pass']; 314 $parsed['port'] = @$info['port']; 315 316 $host = @$info['host']; 317 if (false !== ($pluspos = strpos($host, '+'))) { 318 $parsed['protocol'] = substr($host,0,$pluspos); 319 if ($parsed['protocol'] === 'unix') { 320 $parsed['socket'] = substr($host,$pluspos+1); 321 } else { 322 $parsed['hostspec'] = substr($host,$pluspos+1); 323 } 324 } else { 325 $parsed['hostspec'] = $host; 326 } 327 328 if (isset($info['path'])) { 329 $parsed['database'] = substr($info['path'], 1); // remove first char, which is '/' 330 } 331 332 if (isset($info['query'])) { 333 $opts = explode('&', $info['query']); 334 foreach ($opts as $opt) { 335 list($key, $value) = explode('=', $opt); 336 if (!isset($parsed[$key])) { // don't allow params overwrite 337 $parsed[$key] = urldecode($value); 338 } 339 } 340 } 358 341 359 342 return $parsed; branches/1.0/lib/vendor/creole/CreoleTypes.php
r6003 r6010 122 122 * @return int Creole native type (e.g. Types::LONGVARCHAR, Types::BINARY, etc.). 123 123 */ 124 abstract static function getType($nativeType); 124 public static function getType($nativeType) { 125 throw new Exception('This method must be overridden in subclasses!'); // abstract static not allowed since PHP 5.2 126 } 125 127 126 128 /** … … 131 133 * @return string Native type string. 132 134 */ 133 abstract static function getNativeType($creoleType); 135 public static function getNativeType($creoleType) { 136 throw new Exception('This method must be overridden in subclasses!'); // abstract static not allowed since PHP 5.2 137 } 134 138 135 139 /** branches/1.0/lib/vendor/creole/drivers/mysql/MySQLResultSet.php
r6003 r6010 94 94 function close() 95 95 { 96 @mysql_free_result($this->result); 96 if(is_resource($this->result)) 97 @mysql_free_result($this->result); 97 98 $this->fields = array(); 98 99 } branches/1.0/lib/vendor/creole/drivers/mysqli/MySQLiConnection.php
r6003 r6010 33 33 */ 34 34 class MySQLiConnection extends ConnectionCommon implements Connection { 35 /** Current database (used in mysqli_select_db()). */ 36 private $database; 35 37 36 38 /** … … 54 56 $dbhost = null; 55 57 58 56 59 if (isset($dsninfo['protocol']) && $dsninfo['protocol'] == 'unix') { 57 60 $dbhost = ':' . $dsninfo['socket']; … … 70 73 $socket = !empty($dsninfo['socket']) ? $dsninfo['socket'] : null; 71 74 $database = !empty($dsninfo['database']) ? $dsninfo['database'] : null; 72 75 73 76 $encoding = !empty($dsninfo['encoding']) ? $dsninfo['encoding'] : null; 74 77 75 78 @ini_set('track_errors', true); 76 79 77 80 $conn = mysqli_connect($host, $user, $pw, $database, $port, $socket); 78 81 79 @ini_restore('track_errors');80 81 if ( !$conn) {82 @ini_restore('track_errors'); 83 84 if (empty($conn)) { 82 85 if (($err = @mysqli_error()) != '') { 83 86 throw new SQLException("connect failed", $err); … … 88 91 } 89 92 } 90 93 94 if ($dsninfo['database']) { 95 if (!@mysqli_select_db($conn, $dsninfo['database'])) { 96 switch(mysqli_errno($conn)) { 97 case 1049: 98 $exc = new SQLException("no such database", mysqli_error($conn)); 99 break; 100 case 1044: 101 $exc = new SQLException("access violation", mysqli_error($conn)); 102 break; 103 default: 104 $exc = new SQLException("cannot select database", mysqli_error($conn)); 105 } 106 107 throw $exc; 108 109 } 110 111 // fix to allow calls to different databases in the same script 112 $this->database = $dsninfo['database']; 113 } 114 91 115 $this->dblink = $conn; 92 116 93 117 if ($encoding) { 94 118 $this->executeUpdate("SET NAMES " . $encoding); … … 168 192 $this->lastQuery = $sql; 169 193 194 if ($this->database) { 195 if (!@mysqli_select_db($this->dblink, $this->database)) { 196 throw new SQLException('No database selected', mysqli_error($this->dblink)); 197 } 198 } 199 170 200 $result = @mysqli_query($this->dblink, $sql); 171 201 … … 184 214 $this->lastQuery = $sql; 185 215 216 if ($this->database) { 217 if (!@mysqli_select_db($this->dblink, $this->database)) { 218 throw new SQLException('No database selected', mysqli_error($this->dblink)); 219 } 220 } 221 186 222 $result = @mysqli_query($this->dblink, $sql); 187 223 … … 212 248 protected function commitTrans() 213 249 { 250 if ($this->database) { 251 if (!@mysqli_select_db($this->dblink, $this->database)) { 252 throw new SQLException('No database selected', mysqli_error($this->dblink)); 253 } 254 } 255 214 256 if (!mysqli_commit($this->dblink)) { 215 257 throw new SQLException('Can not commit transaction', mysqli_error($this->dblink)); 216 258 } 259 217 260 mysqli_autocommit($this->dblink, TRUE); 218 261 } … … 225 268 protected function rollbackTrans() 226 269 { 270 if ($this->database) { 271 if (!@mysqli_select_db($this->dblink, $this->database)) { 272 throw new SQLException('No database selected', mysqli_error($this->dblink)); 273 } 274 } 275 227 276 if (!mysqli_rollback($this->dblink)) { 228 277 throw new SQLException('Could not rollback transaction', mysqli_error($this->dblink)); 229 278 } 279 230 280 mysqli_autocommit($this->dblink, TRUE); 231 281 } branches/1.0/lib/vendor/creole/drivers/mysqli/metadata/MySQLiTableInfo.php
r6003 r6010 35 35 require_once 'creole/metadata/ColumnInfo.php'; 36 36 require_once 'creole/drivers/mysql/MySQLTypes.php'; 37 38 if (!@mysqli_select_db($this->conn->getResource(), $this->dbname)) { 39 throw new SQLException('No database selected'); 40 } 37 41 38 42 // To get all of the attributes we need, we use … … 87 91 } 88 92 93 if (!@mysqli_select_db($this->conn->getResource(), $this->dbname)) { 94 throw new SQLException('No database selected'); 95 } 96 89 97 // Primary Keys 90 98 $res = mysqli_query($this->conn->getResource(), "SHOW KEYS FROM " . $this->name); … … 112 120 $this->initColumns(); 113 121 } 114 122 123 if (!@mysqli_select_db($this->conn->getResource(), $this->dbname)) { 124 throw new SQLException('No database selected'); 125 } 126 115 127 // Indexes 116 128 $res = mysqli_query($this->conn->getResource(), "SHOW INDEX FROM " . $this->name); branches/1.0/lib/vendor/creole/drivers/oracle/OCI8Connection.php
r6003 r6010 70 70 $pw = $dsninfo[ 'password' ]; 71 71 $hostspec = $dsninfo[ 'hostspec' ]; 72 $port = $dsninfo[ 'port' ]; 72 73 $db = $dsninfo[ 'database' ]; 73 74 … … 75 76 ? 'oci_pconnect' 76 77 : 'oci_connect'; 78 $encoding = !empty($dsninfo['encoding']) ? $dsninfo['encoding'] : null; 79 80 @ini_set( 'track_errors', true ); 77 81 78 $encoding = !empty($dsninfo['encoding']) ? $dsninfo['encoding'] : null; 79 80 @ini_set( 'track_errors', true ); 82 if ( $hostspec && $port ) 83 { 84 $hostspec .= ':' . $port; 85 } 81 86 82 87 if ( $db && $hostspec && $user && $pw ) branches/1.0/lib/vendor/creole/drivers/oracle/OCI8Types.php
r6003 r6010 45 45 'raw' => CreoleTypes::VARBINARY, 46 46 'longraw' => CreoleTypes::LONGVARBINARY, 47 'date' => CreoleTypes::TIMESTAMP, 47 'date' => CreoleTypes::DATE, 48 'timestamp' => CreoleTypes::TIMESTAMP, 48 49 'blob' => CreoleTypes::BLOB, 49 50 'clob' => CreoleTypes::CLOB, … … 62 63 public static function getType($nativeType) 63 64 { 64 $t = strtolower($nativeType); 65 $t = str_replace(' ', '', strtolower($nativeType)); 66 if ( substr($t, 0, 9) == 'timestamp' ) return CreoleTypes::TIMESTAMP; 65 67 if (isset(self::$typeMap[$t])) { 66 68 return self::$typeMap[$t]; branches/1.0/lib/vendor/creole/drivers/sqlite/SQLiteResultSet.php
r6003 r6010 116 116 { 117 117 $this->fields = array(); 118 $this->result = null; 118 119 } 119 120 } branches/1.0/lib/vendor/creole/drivers/sqlite/metadata/SQLiteTableInfo.php
r6003 r6010 43 43 // the second will fill in some more details. 44 44 45 $sql = 'PRAGMA table_info('.$this->name.')';45 $sql = "PRAGMA table_info('".$this->name."')"; 46 46 47 47 $res = sqlite_query($this->conn->getResource(), $sql); … … 67 67 $type = $fulltype; 68 68 } 69 69 // If column is primary key and of type INTEGER, it is auto increment 70 // See: http://sqlite.org/faq.html#q1 71 $is_auto_increment = ($row['pk'] == 1 && $fulltype == 'INTEGER'); 70 72 $not_null = $row['notnull']; 71 73 $is_nullable = !$not_null; … … 104 106 if (!$this->colsLoaded) $this->initColumns(); 105 107 106 $sql = 'PRAGMA index_list('.$this->name.')';108 $sql = "PRAGMA index_list('".$this->name."')"; 107 109 $res = sqlite_query($this->conn->getResource(), $sql); 108 110 … … 112 114 113 115 // get columns for that index 114 $res2 = sqlite_query($this->conn->getResource(), 'PRAGMA index_info('.$name.')');116 $res2 = sqlite_query($this->conn->getResource(), "PRAGMA index_info('$name')"); 115 117 while($row2 = sqlite_fetch_array($res2, SQLITE_ASSOC)) { 116 118 $colname = $row2['name']; branches/1.0/lib/vendor/creole/metadata/DatabaseInfo.php
r6003 r6010 140 140 public function hasTable($name) 141 141 { 142 if(!$this->tablesLoaded) $this->initTables(); 142 143 return isset($this->tables[strtoupper($name)]); 143 144 }

