r15095 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r15094‎ | r15095 | r15096 >
Date:17:06, 27 June 2006
Author:greg
Status:old
Tags:
Comment:
Add tableExists and fieldExists methods
Modified paths:
  • /trunk/phase3/includes/DatabasePostgres.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/DatabasePostgres.php
@@ -7,9 +7,6 @@
88 * than MySQL ones, some of them should be moved to parent
99 * Database class.
1010 *
11 - * STATUS: Working PG implementation of MediaWiki
12 - * TODO: Installer support
13 - *
1411 * @package MediaWiki
1512 */
1613
@@ -18,10 +15,6 @@
1916 */
2017 require_once( 'Database.php' );
2118
22 -/**
23 - *
24 - * @package MediaWiki
25 - */
2619 class DatabasePostgres extends Database {
2720 var $mInsertId = NULL;
2821 var $mLastResult = NULL;
@@ -191,6 +184,7 @@
192185 }
193186
194187 function fieldInfo( $table, $field ) {
 188+ return false;
195189 throw new DBUnexpectedError($this, 'Database::fieldInfo() error : mysql_fetch_field() not implemented for postgre' );
196190 /*
197191 $res = $this->query( "SELECT * FROM '$table' LIMIT 1" );
@@ -439,6 +433,41 @@
440434 $searchpath=$this->makeList($schemas,LIST_NAMES);
441435 $this->query("SET search_path = $searchpath");
442436 }
 437+
 438+ /**
 439+ * Query whether a given table exists
 440+ */
 441+ function tableExists( $table, $fname = 'DatabasePostgres:tableExists' ) {
 442+ global $wgDBschema;
 443+ $stable = preg_replace("/'/", "''", $table);
 444+ $SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n "
 445+ . "WHERE c.relnamespace = n.oid AND c.relname = '$stable AND n.nspname = '$wgDBschema'";
 446+ $res = $this->query( $SQL, $fname );
 447+ if ($res) {
 448+ $this->freeResult( $res );
 449+ return true;
 450+ }
 451+ return false;
 452+ }
 453+
 454+ /**
 455+ * Query whether a given column exists
 456+ */
 457+ function fieldExists( $table, $field, $fname = 'DatabasePostgres::fieldExists' ) {
 458+ global $wgDBschema;
 459+ $stable = preg_replace("/'/", "''", $table);
 460+ $scol = preg_replace("/'/", "''", $field);
 461+ $SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n, pg_catalog.pg_attribute a "
 462+ . "WHERE c.relnamespace = n.oid AND c.relname = '$stable' AND n.nspname = '$wgDBschema' "
 463+ . "AND a.attrelid = c.oid AND a.attname = '$safecol'";
 464+ $res = $this->query( $SQL, $fname );
 465+ if ($res) {
 466+ $this->freeResult( $res );
 467+ return true;
 468+ }
 469+ return false;
 470+ }
 471+
443472 }
444473
445474 ?>