The tableExists() method (line 364 of /drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php) attempts to differentiate between temporary tables and regular tables by checking for a '#' as the first value in the $table array. However, it appears that $table won't necessarily always be an array, which will occasionally result in the aforementioned PHP notice. The simple fix would be to first check if $table is an array before operating on it as such.

Comments

afireintheattic created an issue. See original summary.

afireintheattic’s picture

StatusFileSize
new656 bytes

Patch is attached.

beakerboy’s picture

Do you have a test case for this? I would like to be able to force the error to happen and then ensure that your patch fixes the problem without side effects. The way I read the code, $table is always a string, never an array. Indexing the string with [0] will grab the first character from the string to see if it is a ‘#’. Somehow, some function is passing NULL in as the table name (according to the backtrace you supplied). If anything, adding

if (empty($table)){
  return false;
}

is probably the way to fix this because I think your is_array() will always evaluate false, and the existance of temporary tables will always be false.

beakerboy’s picture

Version: 8.x-1.0-rc5 » 8.x-1.x-dev
Status: Active » Needs work

Your patch causes a failure in an existing Kernel Test

/**
   * Test the temporary table functionality.
   */
  public function testTemporaryTables() {

    $query = $this->connection->select('test_task', 't');
    $query->fields('t');

    $table = $this->connection->queryTemporary((string) $query);

    // First assert that the table exists.
    $this->assertTRUE(db_table_exists($table), 'The temporary table exists.');
}

  • Beakerboy committed 0ae26f3 on 8.x-1.x
    Issue #3129649 by afireintheattic, Beakerboy: Notice: Trying to access...
beakerboy’s picture

Status: Needs work » Fixed

I merged in my fix. Thanks for bringing this to my attention.

afireintheattic’s picture

StatusFileSize
new678 bytes

Great! As I'm trying to stay locked in at an RC release instead of using the dev branch, I rolled a patch file off of your fix that I can use in my composer.json until this gets rolled into a release. Thanks for the help!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.