buildTableNameCondition example

/** * Check if a table exists. * * @param $table * The name of the table in drupal (no prefixing). * * @return bool * TRUE if the given table exists, otherwise FALSE. */
  public function tableExists($table) {
    $condition = $this->buildTableNameCondition($table);
    $condition->compile($this->connection, $this);
    // Normally, we would heartily discourage the use of string     // concatenation for conditionals like this however, we     // couldn't use \Drupal::database()->select() here because it would prefix     // information_schema.tables and the query would fail.     // Don't use {} around information_schema.tables table.     return (bool) $this->connection->query("SELECT 1 FROM information_schema.tables WHERE " . (string) $condition$condition->arguments())->fetchField();
  }

  /** * Finds all tables that are like the specified base table name. * * @param string $table_expression * A case-insensitive pattern against which table names are compared. Both * '_' and '%' are treated like wildcards in MySQL 'LIKE' expressions, where * '_' matches any single character and '%' matches an arbitrary number of * characters (including zero characters). So 'foo%bar' matches table names * like 'foobar', 'fooXBar', 'fooXBaR', or 'fooXxBar'; whereas 'foo_bar' * matches 'fooXBar' and 'fooXBaR' but not 'fooBar' or 'fooXxxBar'. * * @return array * Both the keys and the values are the matching tables. */
      $comment = Unicode::truncate($this->connection->prefixTables($comment)$length, TRUE, TRUE);
    }
    // Remove semicolons to avoid triggering multi-statement check.     $comment = strtr($comment[';' => '.']);
    return $this->connection->quote($comment);
  }

  /** * Retrieve a table or column comment. */
  public function getComment($table$column = NULL) {
    $condition = $this->buildTableNameCondition($table);
    if (isset($column)) {
      $condition->condition('column_name', $column);
      $condition->compile($this->connection, $this);
      // Don't use {} around information_schema.columns table.       return $this->connection->query("SELECT column_comment AS column_comment FROM information_schema.columns WHERE " . (string) $condition$condition->arguments())->fetchField();
    }
    $condition->compile($this->connection, $this);
    // Don't use {} around information_schema.tables table.     $comment = $this->connection->query("SELECT table_comment AS table_comment FROM information_schema.tables WHERE " . (string) $condition$condition->arguments())->fetchField();
    // Work-around for MySQL 5.0 bug http://bugs.mysql.com/bug.php?id=11379     return preg_replace('/; InnoDB free:.*$/', '', $comment);
  }
Home | Imprint | This part of the site doesn't use cookies.