* Fixed fieldInfo() on Postgres not using tableName() and thus failing for table user, for example.
* Made fieldInfo() on MySQL return false instead of throwing a query error if table does not exist. This is consistent with other databases' behaviour.
/**
* Determines whether a field exists in a table
- * Usually aborts on failure
- * If errors are explicitly ignored, returns NULL on failure
+ * @param $table: table name
+ * @param $filed: filed to check on that table
+ * @param $fname: calling function name (optional)
+ * @return bool: whether $table has filed $field
*/
function fieldExists( $table, $field, $fname = 'Database::fieldExists' ) {
- $table = $this->tableName( $table );
- $res = $this->query( 'DESCRIBE '.$table, $fname );
- if ( !$res ) {
- return null;
- }
-
- $found = false;
-
- while ( $row = $this->fetchObject( $res ) ) {
- if ( $row->Field == $field ) {
- $found = true;
- break;
- }
- }
- return $found;
+ $info = $this->fieldInfo( $table, $field );
+ return (bool)$info;
}
/**
* setFakeSlaveLag [Done]
* setFakeMaster [Done]
*
- * Reflection: 6 / 6
- * fieldExists [Done]
+ * Reflection: 5 / 5
* indexInfo [Done]
* fieldInfo [Done]
* fieldType [Done]
# Reflection
######################################
- /**
- * Query whether a given column exists in the mediawiki schema
- * @param $table String: name of the table
- * @param $field String: name of the column
- * @param $fname String: function name for logging and profiling
- */
- public function fieldExists( $table, $field, $fname = 'DatabaseIbm_db2::fieldExists' ) {
- $table = $this->tableName( $table );
- $schema = $this->mSchema;
- $etable = preg_replace("/'/", "''", $table);
- $eschema = preg_replace("/'/", "''", $schema);
- $ecol = preg_replace("/'/", "''", $field);
- $sql = <<<SQL
-SELECT 1 as fieldexists
-FROM sysibm.syscolumns sc
-WHERE sc.name='$ecol' AND sc.tbname='$etable' AND sc.tbcreator='$eschema'
-SQL;
- $res = $this->query( $sql, $fname );
- $count = $res ? $this->numRows($res) : 0;
- if ($res)
- $this->freeResult( $res );
- return $count;
- }
-
/**
* Returns information about an index
* If errors are explicitly ignored, returns NULL on failure
function fieldInfo( $table, $field ) {
$table = $this->tableName( $table );
- $res = $this->query( "SELECT * FROM $table LIMIT 1" );
+ $res = $this->query( "SELECT * FROM $table LIMIT 1", __METHOD__, true );
+ if ( !$res ) {
+ return false;
+ }
$n = mysql_num_fields( $res->result );
for( $i = 0; $i < $n; $i++ ) {
$meta = mysql_fetch_field( $res->result, $i );
return $this->fieldInfoMulti ($table, $field);
}
- function fieldExists( $table, $field, $fname = 'DatabaseOracle::fieldExists' ) {
- return (bool)$this->fieldInfo( $table, $field, $fname );
- }
-
function begin( $fname = '' ) {
$this->mTrxLevel = 1;
}
AND relname=%s
AND attname=%s;
SQL;
+
+ $table = $db->tableName( $table );
$res = $db->query(sprintf($q,
$db->addQuotes($wgDBmwschema),
$db->addQuotes($table),
return $owner;
}
- /**
- * Query whether a given column exists in the mediawiki schema
- */
- function fieldExists( $table, $field, $fname = 'DatabasePostgres::fieldExists' ) {
- global $wgDBmwschema;
- $etable = preg_replace("/'/", "''", $table);
- $eschema = preg_replace("/'/", "''", $wgDBmwschema);
- $ecol = preg_replace("/'/", "''", $field);
- $SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n, pg_catalog.pg_attribute a "
- . "WHERE c.relnamespace = n.oid AND c.relname = '$etable' AND n.nspname = '$eschema' "
- . "AND a.attrelid = c.oid AND a.attname = '$ecol'";
- $res = $this->query( $SQL, $fname );
- $count = $res ? $res->numRows() : 0;
- if ($res)
- $this->freeResult( $res );
- return $count;
- }
-
function fieldInfo( $table, $field ) {
return PostgresField::fromText($this, $table, $field);
}
return $ver;
}
- /**
- * Query whether a given column exists in the mediawiki schema
- */
- function fieldExists( $table, $field, $fname = '' ) {
- $info = $this->fieldInfo( $table, $field );
- return (bool)$info;
- }
-
/**
* Get information about a given field
* Returns false if the field does not exist.