Improve tableExists() for MySQL
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 20 Sep 2016 17:30:00 +0000 (10:30 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 20 Sep 2016 17:37:41 +0000 (17:37 +0000)
Use SHOW TABLES to avoid log spam when the table does not exist.
This should make the CLI jenkins log a bit more readable.

Change-Id: I027a9d0af0e42959e9f03cebb295218068a263d3

includes/libs/rdbms/database/DatabaseMysqlBase.php

index 2d19081..9be3ede 100644 (file)
@@ -518,6 +518,12 @@ abstract class DatabaseMysqlBase extends DatabaseBase {
                return (int)$rows;
        }
 
+       function tableExists( $table, $fname = __METHOD__ ) {
+               $encLike = $this->buildLike( $table );
+
+               return $this->query( "SHOW TABLES $encLike", $fname )->numRows() > 0;
+       }
+
        /**
         * @param string $table
         * @param string $field