当前位置: 首页>>代码示例>>PHP>>正文


PHP Connection::tablePrefix方法代码示例

本文整理汇总了PHP中Drupal\Core\Database\Connection::tablePrefix方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::tablePrefix方法的具体用法?PHP Connection::tablePrefix怎么用?PHP Connection::tablePrefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Database\Connection的用法示例。


在下文中一共展示了Connection::tablePrefix方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getTables

 /**
  * Returns a list of tables, not including those set to be excluded.
  *
  * @return array
  *   An array of table names.
  */
 protected function getTables()
 {
     $pattern = $this->connection->tablePrefix() . '%';
     $tables = array_values($this->connection->schema()->findTables($pattern));
     foreach ($tables as $key => $table) {
         // The prefix is removed for the resultant script.
         $table = $tables[$key] = str_replace($this->connection->tablePrefix(), '', $table);
         // Remove any explicitly excluded tables.
         foreach ($this->excludeTables as $pattern) {
             if (preg_match('/^' . $pattern . '$/', $table)) {
                 unset($tables[$key]);
             }
         }
     }
     return $tables;
 }
开发者ID:jeyram,项目名称:camp-gdl,代码行数:22,代码来源:DbDumpCommand.php

示例2: findFreeTable

  /**
   * Finds a free table name using a certain prefix and name base.
   *
   * Used as a helper method in fieldsUpdated().
   *
   * MySQL 5.0 imposes a 64 characters length limit for table names, PostgreSQL
   * 8.3 only allows 62 bytes. Therefore, always return a name at most 62
   * bytes long.
   *
   * @param string $prefix
   *   Prefix for the table name. Must only consist of characters valid for SQL
   *   identifiers.
   * @param string $name
   *   Name to base the table name on.
   *
   * @return string
   *   A database table name that isn't in use yet.
   */
  protected function findFreeTable($prefix, $name) {
    // A DB prefix might further reduce the maximum length of the table name.
    $maxbytes = 62;
    if ($db_prefix = $this->database->tablePrefix()) {
      // Use strlen() instead of Unicode::strlen() since we want to measure
      // bytes, not characters.
      $maxbytes -= strlen($db_prefix);
    }

    $base = $table = Unicode::truncateBytes($prefix . Unicode::strtolower(preg_replace('/[^a-z0-9]/i', '_', $name)), $maxbytes);
    $i = 0;
    while ($this->database->schema()->tableExists($table)) {
      $suffix = '_' . ++$i;
      $table = Unicode::truncateBytes($base, $maxbytes - strlen($suffix)) . $suffix;
    }
    return $table;
  }
开发者ID:jkyto,项目名称:agolf,代码行数:35,代码来源:Database.php

示例3: findTables

 /**
  * Finds all tables that are like the specified base table name.
  *
  * @param string $table_expression
  *   An SQL expression, for example "cache_%" (without the quotes).
  *
  * @return array
  *   Both the keys and the values are the matching tables.
  */
 public function findTables($table_expression)
 {
     // Load all the tables up front in order to take into account per-table
     // prefixes. The actual matching is done at the bottom of the method.
     $condition = $this->buildTableNameCondition('%', 'LIKE');
     $condition->compile($this->connection, $this);
     $individually_prefixed_tables = $this->connection->getUnprefixedTablesMap();
     $default_prefix = $this->connection->tablePrefix();
     $default_prefix_length = strlen($default_prefix);
     $tables = [];
     // Normally, we would heartily discourage the use of string
     // concatenation for conditionals like this however, we
     // couldn't use db_select() here because it would prefix
     // information_schema.tables and the query would fail.
     // Don't use {} around information_schema.tables table.
     $results = $this->connection->query("SELECT table_name FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments());
     foreach ($results as $table) {
         // Take into account tables that have an individual prefix.
         if (isset($individually_prefixed_tables[$table->table_name])) {
             $prefix_length = strlen($this->connection->tablePrefix($individually_prefixed_tables[$table->table_name]));
         } elseif ($default_prefix && substr($table->table_name, 0, $default_prefix_length) !== $default_prefix) {
             // This table name does not start the default prefix, which means that
             // it is not managed by Drupal so it should be excluded from the result.
             continue;
         } else {
             $prefix_length = $default_prefix_length;
         }
         // Remove the prefix from the returned tables.
         $unprefixed_table_name = substr($table->table_name, $prefix_length);
         // The pattern can match a table which is the same as the prefix. That
         // will become an empty string when we remove the prefix, which will
         // probably surprise the caller, besides not being a prefixed table. So
         // remove it.
         if (!empty($unprefixed_table_name)) {
             $tables[$unprefixed_table_name] = $unprefixed_table_name;
         }
     }
     // Convert the table expression from its SQL LIKE syntax to a regular
     // expression and escape the delimiter that will be used for matching.
     $table_expression = str_replace(array('%', '_'), array('.*?', '.'), preg_quote($table_expression, '/'));
     $tables = preg_grep('/^' . $table_expression . '$/i', $tables);
     return $tables;
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:52,代码来源:Schema.php


注:本文中的Drupal\Core\Database\Connection::tablePrefix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。