Set schema search paths

@param string $schema Schema name

@return Index
972653
public function setSchema($schema)
    {
        $schema = func_get_args();
        
        $schema = "'".implode("','", $schema)."'";
        
        $query = $this->getUtilityQuery()->setSchema($schema);
        $this->query($query);
        
        return $this;
    }
1122598
public function setSchema($schema)
    {
        $oldSchema = $this->schema;
        if ($this->schema !== $schema && $this->getPlatform()) {
            $schemaDelimiter = $this->getPlatform()->getSchemaDelimiter();
            $fixHash = function (&$array) use ($schema, $oldSchema, $schemaDelimiter) {
                foreach ($array as $k => $v) {
                    if ($schema && $this->getPlatform()->supportsSchemas()) {
                        if (false === strpos($k, $schemaDelimiter)) {
                            $array[$schema . $schemaDelimiter . $k] = $v;
                            unset($array[$k]);
                        }
                    } elseif ($oldSchema) {
                        if (false !== strpos($k, $schemaDelimiter)) {
                            $array[explode($schemaDelimiter, $k)[1]] = $v;
                            unset($array[$k]);
                        }
                    }
                }
            };

            $fixHash($this->tablesByName);
            $fixHash($this->tablesByLowercaseName);
        }
        parent::setSchema($schema);
    }
1117949
private function addSchema(Schema $schema)
    {
        if (array_key_exists($schema->getName(), $this->schemas)) {
            throw new \Exception(sprintf('Schema "%s" is allready registered.', $schema->getName()));
        }

        $this->schemas[$schema->getName()] = $schema;

        return $this;
    }
1306511
public function schema($schema = null)
    {
        if (func_num_args() === 0) {
            return $this->collection->schema();
        }

        return $this->collection->schema($schema);
    }
452522
public function visitSchema(Schema $schema)
    {
        return new Schema(
            $this->transformConstraintArray($schema->constraints()),
            $schema->defaultValue(),
            $schema->title(),
            $schema->description()
        );
    }
904059
protected function hydrateSchemaFromAssoc(array $schema) {
		/** @var \Cake\ORM\AssociationCollection|\Cake\ORM\Association[] $associations */
		$associations = $this->getConfig('associations');

		foreach ($associations as $association) {
			try {
				$entityClass = '\\' . ltrim($association->getTarget()->getEntityClass(), '\\');

				if ($entityClass === '\Cake\ORM\Entity') {
					$namespace = Configure::read('App.namespace');

					list($plugin) = pluginSplit($association->getTarget()->getRegistryAlias());
					if ($plugin !== null) {
						$namespace = $plugin;
					}
					$namespace = str_replace('/', '\\', trim($namespace, '\\'));

					$entityClass = $this->_entityName($association->getTarget()->getAlias());
					$entityClass = '\\' . $namespace . '\Model\Entity\\' . $entityClass;

					if (!class_exists($entityClass)) {
						$entityClass = '\Cake\ORM\Entity';
					}
				}

				$schema[$association->getProperty()] = [
					'kind' => 'association',
					'association' => $association,
					'type' => $entityClass
				];
			} catch (Exception $exception) {
				continue;
			}
		}

		return $schema;
	}
1224581
public function visitSchema(Schema $schema)
    {
        $result = $this->result($schema);
        if (null !== $result) {
            return $result;
        }

        $result = $this->register($schema, $this->createResult());

        foreach ($schema->constraints() as $constraint) {
            $result = $result->merge($constraint->accept($this));
        }

        if ($result->isValid()) {
            $result->addMatch($this->createMatch($schema));
        }

        return $result;
    }
633293
public function getSchemaSearchPaths()
    {
        $params = $this->_conn->getParams();
        $schema = explode(',', $this->_conn->fetchColumn('SHOW search_path'));

        if (isset($params['user'])) {
            $schema = str_replace('"$user"', $params['user'], $schema);
        }

        return array_map('trim', $schema);
    }
1034574
public function getTables($schema = null)
    {
        $sql = 'SELECT' . " tbl_name FROM sqlite_master WHERE type = 'table' ORDER BY tbl_name";
        $tables = [];
        foreach ($this->query($sql, [], \PDO::FETCH_ASSOC) as $row) {
            $tables[] = $row['tbl_name'];
        }

        return $tables;
    }
810840
public function upgradeSchema(Schema $schema)
    {
        /* Add query log db table */

        try {
            $table = $schema->getTable('SystemDatabaseQueryLog');
        } catch (Exception $e) {
            $table = null;
        }
        if (!($table instanceof Table)) {
            $ql = $schema->createTable('SystemDatabaseQueryLog');
            $ql->addColumn('query', 'text');
            $ql->addColumn('params', 'text', ['notnull' => false]);
            $ql->addColumn('executionMS', 'string');
        }
    }
1166113
private function findTableSchemas($schema = null)
    {
        $tableNames = $this->getTableNames($schema, true);

        if (is_callable($this->tableNameFilter)) {
            $tableNames = array_filter($tableNames,
                function($tableName) use ($schema) {
                    return call_user_func($this->tableNameFilter, $tableName, $schema);
                }
            );
        }

        $tableSchemas = array_map(
            function($tableName) use ($schema) {
                $tableSchema = new TableSchema();
                $tableNameFull = $schema === null ? $tableName : "$schema.$tableName";
                $this->resolveTableNames($tableSchema, $tableNameFull);
                return $tableSchema;
            },
            $tableNames);

        return $tableSchemas;
    }
610342
public function parse($schema)
    {
        $fields = $this->splitIntoFields($schema);

        foreach ($fields as $field) {
            $segments = $this->parseSegments($field);

            if ($this->fieldNeedsForeignConstraint($segments)) {
                unset($segments['options']['foreign']);

                // If the user wants a foreign constraint, then
                // we'll first add the regular field.
                $this->addField($segments);

                // And then add another field for the constraint.
                $this->addForeignConstraint($segments);

                continue;
            }

            $this->addField($segments);
        }

        return $this->schema;
    }
472406
public function schema($schema = null) {
        if (!func_num_args()) {
            return $this->_schema;
        }
        $this->_schema = $schema;
        return $this;
    }
1262377
public function upgradeSchema(Schema $schema)
    {
        $table = $schema->getTable('FileImageThumbnailPaths');
        if ($table->hasIndex('thumbnailPathID')) {
            $table->dropIndex('thumbnailPathID');
        }
        if (!$table->hasColumn('thumbnailFormat')) {
            $table->addColumn(
                'thumbnailFormat',
                'string',
                [
                    'notnull' => true,
                    'default' => '',
                    'length' => 5,
                ]
            );
            $table->setPrimaryKey([
                'fileID',
                'fileVersionID',
                'thumbnailTypeHandle',
                'storageLocationID',
                'thumbnailFormat',
            ]);
        }
    }
1051346
final public function preDown(Schema $schema)
    {
        $this->prepare(array_map(function (string $migration) : string {
            return $this->getFullPath($migration);
        }, $this->getDowngradeMigrations()));
    }
518240
public function up(Schema $schema)
    {
        /*
         * Migration is not critical
         * Old format for storing image files to the new format
         *
         * Old format(date added image):
         *    media/{Y}/{m}/
         *
         * New Format(date added item):
         *    media/{Y}/{m}/{d}/{His}/
         */

        // move covers
        $items = $this->connection->fetchAll('
            SELECT
                `id`,
                `cover`,
                `date_add`
            FROM
                `item`
            WHERE
                `cover` IS NOT NULL AND
                `cover` != "" AND
                `cover`  NOT LIKE "example/%"'
        );
        foreach ($items as $item) {
            $path = date('Y/m/d/His/', strtotime($item['date_add']));
            $file = new File($this->media_dir.$item['cover']);
            $file->move($this->media_dir.$path);
            $this->addSql('
                UPDATE
                    `item`
                SET
                    `cover` = ?
                WHERE
                    `id` = ?',
                [
                    $path.$file->getBasename(),
                    $item['id'],
                ]
            );
        }

        // move images
        $images = $this->connection->fetchAll('
            SELECT
                im.`id`,
                im.`source`,
                i.`date_add`
            FROM
                `item` AS `i`
            INNER JOIN
                `image` AS `im`
                ON
                    im.`item` = i.`id`'
        );
        foreach ($images as $image) {
            $path = date('Y/m/d/His/', strtotime($image['date_add']));
            $file = new File($this->media_dir.$image['source']);
            $file->move($this->media_dir.$path);
            $this->addSql('
                UPDATE
                    `image`
                SET
                    `source` = ?
                WHERE
                    `id` = ?',
                [
                    $path.$file->getBasename(),
                    $image['id'],
                ]
            );
        }

        // skip if no data
        $this->skipIf(!($items && $images), 'No data to migrate');
    }
114115
protected function generateProperties(array $schema)
    {
        $directory = $this->getMappingDirectory('Property');
        $this->generateAbstractProperty($directory);
        foreach ($schema['properties'] as $property => $data) {
            $this->generateProperty($property, $data, $directory, $schema['datatypes']);
        }
    }