Index: trunk/phase3/includes/db/DatabaseMysql.php |
— | — | @@ -262,7 +262,10 @@ |
263 | 263 | |
264 | 264 | function fieldInfo( $table, $field ) { |
265 | 265 | $table = $this->tableName( $table ); |
266 | | - $res = $this->query( "SELECT * FROM $table LIMIT 1" ); |
| 266 | + $res = $this->query( "SELECT * FROM $table LIMIT 1", __METHOD__, true ); |
| 267 | + if ( !$res ) { |
| 268 | + return false; |
| 269 | + } |
267 | 270 | $n = mysql_num_fields( $res->result ); |
268 | 271 | for( $i = 0; $i < $n; $i++ ) { |
269 | 272 | $meta = mysql_fetch_field( $res->result, $i ); |
Index: trunk/phase3/includes/db/DatabaseOracle.php |
— | — | @@ -905,10 +905,6 @@ |
906 | 906 | return $this->fieldInfoMulti ($table, $field); |
907 | 907 | } |
908 | 908 | |
909 | | - function fieldExists( $table, $field, $fname = 'DatabaseOracle::fieldExists' ) { |
910 | | - return (bool)$this->fieldInfo( $table, $field, $fname ); |
911 | | - } |
912 | | - |
913 | 909 | function begin( $fname = '' ) { |
914 | 910 | $this->mTrxLevel = 1; |
915 | 911 | } |
Index: trunk/phase3/includes/db/DatabasePostgres.php |
— | — | @@ -31,6 +31,8 @@ |
32 | 32 | AND relname=%s |
33 | 33 | AND attname=%s; |
34 | 34 | SQL; |
| 35 | + |
| 36 | + $table = $db->tableName( $table ); |
35 | 37 | $res = $db->query(sprintf($q, |
36 | 38 | $db->addQuotes($wgDBmwschema), |
37 | 39 | $db->addQuotes($table), |
— | — | @@ -1264,24 +1266,6 @@ |
1265 | 1267 | return $owner; |
1266 | 1268 | } |
1267 | 1269 | |
1268 | | - /** |
1269 | | - * Query whether a given column exists in the mediawiki schema |
1270 | | - */ |
1271 | | - function fieldExists( $table, $field, $fname = 'DatabasePostgres::fieldExists' ) { |
1272 | | - global $wgDBmwschema; |
1273 | | - $etable = preg_replace("/'/", "''", $table); |
1274 | | - $eschema = preg_replace("/'/", "''", $wgDBmwschema); |
1275 | | - $ecol = preg_replace("/'/", "''", $field); |
1276 | | - $SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n, pg_catalog.pg_attribute a " |
1277 | | - . "WHERE c.relnamespace = n.oid AND c.relname = '$etable' AND n.nspname = '$eschema' " |
1278 | | - . "AND a.attrelid = c.oid AND a.attname = '$ecol'"; |
1279 | | - $res = $this->query( $SQL, $fname ); |
1280 | | - $count = $res ? $res->numRows() : 0; |
1281 | | - if ($res) |
1282 | | - $this->freeResult( $res ); |
1283 | | - return $count; |
1284 | | - } |
1285 | | - |
1286 | 1270 | function fieldInfo( $table, $field ) { |
1287 | 1271 | return PostgresField::fromText($this, $table, $field); |
1288 | 1272 | } |
Index: trunk/phase3/includes/db/DatabaseIbm_db2.php |
— | — | @@ -291,8 +291,7 @@ |
292 | 292 | * setFakeSlaveLag [Done] |
293 | 293 | * setFakeMaster [Done] |
294 | 294 | * |
295 | | - * Reflection: 6 / 6 |
296 | | - * fieldExists [Done] |
| 295 | + * Reflection: 5 / 5 |
297 | 296 | * indexInfo [Done] |
298 | 297 | * fieldInfo [Done] |
299 | 298 | * fieldType [Done] |
— | — | @@ -1535,30 +1534,6 @@ |
1536 | 1535 | ###################################### |
1537 | 1536 | |
1538 | 1537 | /** |
1539 | | - * Query whether a given column exists in the mediawiki schema |
1540 | | - * @param $table String: name of the table |
1541 | | - * @param $field String: name of the column |
1542 | | - * @param $fname String: function name for logging and profiling |
1543 | | - */ |
1544 | | - public function fieldExists( $table, $field, $fname = 'DatabaseIbm_db2::fieldExists' ) { |
1545 | | - $table = $this->tableName( $table ); |
1546 | | - $schema = $this->mSchema; |
1547 | | - $etable = preg_replace("/'/", "''", $table); |
1548 | | - $eschema = preg_replace("/'/", "''", $schema); |
1549 | | - $ecol = preg_replace("/'/", "''", $field); |
1550 | | - $sql = <<<SQL |
1551 | | -SELECT 1 as fieldexists |
1552 | | -FROM sysibm.syscolumns sc |
1553 | | -WHERE sc.name='$ecol' AND sc.tbname='$etable' AND sc.tbcreator='$eschema' |
1554 | | -SQL; |
1555 | | - $res = $this->query( $sql, $fname ); |
1556 | | - $count = $res ? $this->numRows($res) : 0; |
1557 | | - if ($res) |
1558 | | - $this->freeResult( $res ); |
1559 | | - return $count; |
1560 | | - } |
1561 | | - |
1562 | | - /** |
1563 | 1538 | * Returns information about an index |
1564 | 1539 | * If errors are explicitly ignored, returns NULL on failure |
1565 | 1540 | * @param $table String: table name |
Index: trunk/phase3/includes/db/Database.php |
— | — | @@ -1017,25 +1017,14 @@ |
1018 | 1018 | |
1019 | 1019 | /** |
1020 | 1020 | * Determines whether a field exists in a table |
1021 | | - * Usually aborts on failure |
1022 | | - * If errors are explicitly ignored, returns NULL on failure |
| 1021 | + * @param $table: table name |
| 1022 | + * @param $filed: filed to check on that table |
| 1023 | + * @param $fname: calling function name (optional) |
| 1024 | + * @return bool: whether $table has filed $field |
1023 | 1025 | */ |
1024 | 1026 | function fieldExists( $table, $field, $fname = 'Database::fieldExists' ) { |
1025 | | - $table = $this->tableName( $table ); |
1026 | | - $res = $this->query( 'DESCRIBE '.$table, $fname ); |
1027 | | - if ( !$res ) { |
1028 | | - return null; |
1029 | | - } |
1030 | | - |
1031 | | - $found = false; |
1032 | | - |
1033 | | - while ( $row = $this->fetchObject( $res ) ) { |
1034 | | - if ( $row->Field == $field ) { |
1035 | | - $found = true; |
1036 | | - break; |
1037 | | - } |
1038 | | - } |
1039 | | - return $found; |
| 1027 | + $info = $this->fieldInfo( $table, $field ); |
| 1028 | + return (bool)$info; |
1040 | 1029 | } |
1041 | 1030 | |
1042 | 1031 | /** |
Index: trunk/phase3/includes/db/DatabaseSqlite.php |
— | — | @@ -436,14 +436,6 @@ |
437 | 437 | } |
438 | 438 | |
439 | 439 | /** |
440 | | - * Query whether a given column exists in the mediawiki schema |
441 | | - */ |
442 | | - function fieldExists( $table, $field, $fname = '' ) { |
443 | | - $info = $this->fieldInfo( $table, $field ); |
444 | | - return (bool)$info; |
445 | | - } |
446 | | - |
447 | | - /** |
448 | 440 | * Get information about a given field |
449 | 441 | * Returns false if the field does not exist. |
450 | 442 | */ |