DboSource::fullTableName PHP Method

fullTableName() public method

Gets full table name including prefix
public fullTableName ( Model | string $model, boolean $quote = true, boolean $schema = true ) : string
$model Model | string Either a Model object or a string table name.
$quote boolean Whether you want the table name quoted.
$schema boolean Whether you want the schema name included.
return string Full quoted table name
    public function fullTableName($model, $quote = true, $schema = true)
    {
        if (is_object($model)) {
            $schemaName = $model->schemaName;
            $table = $model->tablePrefix . $model->table;
        } elseif (!empty($this->config['prefix']) && strpos($model, $this->config['prefix']) !== 0) {
            $table = $this->config['prefix'] . strval($model);
        } else {
            $table = strval($model);
        }
        if ($schema && !isset($schemaName)) {
            $schemaName = $this->getSchemaName();
        }
        if ($quote) {
            if ($schema && !empty($schemaName)) {
                if (strstr($table, '.') === false) {
                    return $this->name($schemaName) . '.' . $this->name($table);
                }
            }
            return $this->name($table);
        }
        if ($schema && !empty($schemaName)) {
            if (strstr($table, '.') === false) {
                return $schemaName . '.' . $table;
            }
        }
        return $table;
    }

Usage Example

Example #1
0
/**
 * test Index introspection.
 *
 * @return void
 */
	public function testIndex() {
		$name = $this->Dbo->fullTableName('with_a_key');
		$this->Dbo->query('CREATE TABLE ' . $name . ' ("id" int(11) PRIMARY KEY, "bool" int(1), "small_char" varchar(50), "description" varchar(40) );');
		$this->Dbo->query('CREATE INDEX pointless_bool ON ' . $name . '("bool")');
		$this->Dbo->query('CREATE UNIQUE INDEX char_index ON ' . $name . '("small_char")');
		$expected = array(
			'PRIMARY' => array('column' => 'id', 'unique' => 1),
			'pointless_bool' => array('column' => 'bool', 'unique' => 0),
			'char_index' => array('column' => 'small_char', 'unique' => 1),

		);
		$result = $this->Dbo->index($name);
		$this->assertEqual($expected, $result);
		$this->Dbo->query('DROP TABLE ' . $name);

		$this->Dbo->query('CREATE TABLE ' . $name . ' ("id" int(11) PRIMARY KEY, "bool" int(1), "small_char" varchar(50), "description" varchar(40) );');
		$this->Dbo->query('CREATE UNIQUE INDEX multi_col ON ' . $name . '("small_char", "bool")');
		$expected = array(
			'PRIMARY' => array('column' => 'id', 'unique' => 1),
			'multi_col' => array('column' => array('small_char', 'bool'), 'unique' => 1),
		);
		$result = $this->Dbo->index($name);
		$this->assertEqual($expected, $result);
		$this->Dbo->query('DROP TABLE ' . $name);
	}
All Usage Examples Of DboSource::fullTableName
DboSource