method supporting recursion through all criterions to give
us a string array of tables from each criterion
@return void
6709
private function addCriterionTable(AbstractCriterion $c, array &$s)
    {
        $s[] = $c->getTable();
        foreach ($c->getClauses() as $clause) {
            $this->addCriterionTable($clause, $s);
        }
    }
117987
public function checkRequiredTables() {
        if ($this->requiredTables) {
            $this->out(sprintf('The following tables are required: <info>%s</info>', implode(', ', $this->requiredTables)));
            $this->out('<success>Checking tables...</success>');

            $tables = $this->db->listSources();
            $missing = array();

            foreach ($this->requiredTables as $table) {
                if (!in_array($this->db->config['prefix'] . $table, $tables)) {
                    $missing[] = $table;
                }
            }

            if ($missing) {
                $this->err(sprintf('<error>Missing tables %s; can not proceed</error>', implode(', ', $missing)));
                return false;
            }
        }

        $this->out('<success>Table status good, proceeding...</success>');
        return true;
    }
1038763
public function getJoinString()
    {
        $statement = "";
        
        foreach ($this->join as $i => $join) {
            $statement .= " " . $join['type'] . " " . $join['table'];
            
            if ($join['alias']) {
                $statement .= " AS " . $join['alias'];
            }
            
            // Add ON criteria if specified.
            if ($join['criteria']) {
                $statement .= " ON ";
                
                foreach ($join['criteria'] as $x => $criterion) {
                    // Logically join each criterion with AND.
                    if ($x != 0) {
                        $statement .= " " . self::LOGICAL_AND . " ";
                    }
                    
                    // If the criterion does not include an equals sign, assume a
                    // column name and join against the same column from the previous
                    // table.
                    if (strpos($criterion, '=') === false) {
                        $statement .= $this->getJoinCriteriaUsingPreviousTable($i, $join['table'], $criterion);
                    } else {
                        $statement .= $criterion;
                    }
                }
            }
        }
        
        $statement = trim($statement);
        
        return $statement;
    }
45069
public function createTables()
    {
        $db = $this->getDb();
        $prefixTables = $this->getTablePrefix();

        $tablesAlreadyInstalled = $this->getTablesInstalled();
        $tablesToCreate = $this->getTablesCreateSql();
        unset($tablesToCreate['archive_blob']);
        unset($tablesToCreate['archive_numeric']);

        foreach ($tablesToCreate as $tableName => $tableSql) {
            $tableName = $prefixTables . $tableName;
            if (!in_array($tableName, $tablesAlreadyInstalled)) {
                $db->query($tableSql);
            }
        }
    }
1141030
public function getTables()
    {
        $objResult = $this->query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = current_schema() AND TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME ASC");
        $strToReturn = array();
        while ($strRowArray = $objResult->fetchRow()) {
            array_push($strToReturn, $strRowArray[0]);
        }
        return $strToReturn;
    }
87614
public function optimize($tables = null)
    {
        if ($tables) {
            $db = self::connect();
            if (is_array($tables)) {
                $tables = implode('`,`', $tables);
                $list = $db->query("OPTIMIZE TABLE `{$tables}`");
            } else {
                $list = $db->query("OPTIMIZE TABLE `{$tables}`");
            }
            if ($list) {
                return $tables;
            } else {
                throw new \Exception("data sheet'{$tables}'Repair mistakes please try again!");
            }
        } else {
            throw new \Exception("Please specify the table to be repaired!");
        }
    }
108440
public function init()
    {
        // the table model is an object list
        if (empty($this->table_model)) {
            return false;
        }

        // get a short tag based on the table name
        if (!$this->get_table_short_tag()) return false;

        $this->tpl_replacements['where_statement']    = '';
        $this->tpl_replacements['load_row_list']      = '';
        $this->tpl_replacements['trait_list']         = "\n\nuse " . $this->namespace . "Database;\n\n";
        $this->tpl_replacements['update_insert_list'] = '';

        $i     = 0;
        $count = count($this->table_model);
        // try to fit all possibilities of generated code in here
        // otherwise it would be iterated much more often
        foreach ($this->table_model as $column) {
            // to reduce the use of the strtolower function ;) just do it once
            $property_name = strtolower($column->Field);

            // get a list of properties
            $property_list_unsorted[(string)$property_name] = (string)"\t/**" . ($column->Comment ? self::STD_INTEND_PROPERTIES . " * comment: $column->Comment" : '');
            $property_list_unsorted[(string)$property_name] .= (string)($column->Extra || strtolower($column->Null) == 'no' ? self::STD_INTEND_PROPERTIES . " * Extra: $column->Extra[Not null]" : '');
            $property_list_unsorted[(string)$property_name] .= (string)" " . self::STD_INTEND_PROPERTIES . " * @var $column->Type" . ($column->Key == 'PRI' ? " [PRIMARY KEY]" : '') . self::STD_INTEND_PROPERTIES . " */" . self::STD_INTEND_PROPERTIES . "public $" . $property_name . " = " . $this->get_type_value((($column->Null == 'NO' && !$this->with_null) ? $column->Type : '')) . ";\n\n";

            if ($column->Key == 'PRI') {

                $this->primary_key[] = $column->Field;
                if (!empty($this->where_statement)) {
                    $this->tpl_replacements['where_statement'] .= (string)' AND ';
                }
                // generate generic where statement based on the primary keys
                $this->tpl_replacements['where_statement'] .= (string)"`$column->Field` = '\$this->" . $property_name . "'";
                $this->tpl_replacements['constructor_key_list'] = '';
                $this->tpl_replacements['constructor_key_list'] .= (string)"\t\t" . '$this->' . $property_name . ' = $' . $property_name . ";\n";

            }

            if ($column->Null == 'NO') {
                $this->tpl_replacements['mandatory_fields'][] = (string)$property_name;
            }

            // mysql list for the save function
            $this->tpl_replacements['update_insert_list'] .= (string)"\t\t\$sql .= (\$this->$property_name !== " . (($column->Null == 'NO' && !$this->with_null) ? $this->get_type_value($column->Type) : 'null') . ") ? \"";
            $this->tpl_replacements['update_insert_list'] .= (string)"`$column->Field`= '\" . Database_Tool::db_sanitize(stripslashes(\$this->$property_name)) . \"'";
            $this->tpl_replacements['update_insert_list'] .= (string)($count != $i + 1 ? ', "' : '"') . " : '';\n";

            // get multi keys for assignment
            if ($column->Key == 'MUL') {
                $this->key_list = (string)$column->Field;
            }
            // get multi keys for assignment
            if ($column->Key == 'UNI') {
                $this->key_list = (string)$column->Field;
            }

            // assign the SQL field list
            $this->sql_field_list[] = (string)"`$this->table_short_tag`.`$column->Field`";

            // generates the load row property assignment list
            $this->tpl_replacements['load_row_list'] .= (string)"\t\t\$this->" . strtolower($column->Field) . " = " . (($column->Null == 'NO' && !$this->with_null) ? $this->get_type_value($column->Type, true) : '') . " isset(\$row->" . $column->Field . ") ? \$row->" . $column->Field . " : " . (($column->Null == 'NO' && !$this->with_null) ? $this->get_type_value($column->Type) : 'null') . ";\n";
            $i = $i + 1;
        }
        // remove the last coma
        // add the db to the listing of the class properties
        $property_list_unsorted['db']        = (string)"\t/**" . self::STD_INTEND_PROPERTIES . " * Database object" . self::STD_INTEND_PROPERTIES . "  * @var Object" . self::STD_INTEND_PROPERTIES . " */" . self::STD_INTEND_PROPERTIES . "public \$db = null;\n\n";
        $property_list_unsorted['mandatory'] = (string)"\t/**" . self::STD_INTEND_PROPERTIES . " * list of mandatory fields " . self::STD_INTEND_PROPERTIES . "  * @var array" . self::STD_INTEND_PROPERTIES . " */" . self::STD_INTEND_PROPERTIES . "public \$mandatory_field = array('" . implode("','", $this->tpl_replacements['mandatory_fields']) . "');\n\n";
        // sort alpabetical based on the key
        ksort($property_list_unsorted);
        $this->tpl_replacements['property_list'] = implode("\n\n", $property_list_unsorted);
        unset($property_list_unsorted);

        $this->generate_primary_key_statement();

        // implode the field list
        $this->tpl_replacements['sql_field_list'] = implode(', ', $this->sql_field_list);

        $this->tpl_replacements['constructor_param_list'] = '$' . strtolower(implode("'\n\t\t* @param ', $", $this->primary_key));

        return true;
    }
475305
public function setTables(array $tables)
    {
        $this->tables = array();

        foreach ($tables as $table) {
            $this->addTable($table);
        }
    }
355557
public function main()
    {
        $options = (array)$this->params;
        $destination = normalizePath("{$options['destination']}/");

        if (is_string($options['tables'])) {
            $options['tables'] = explode(',', $options['tables']);
        }

        if (is_string($options['no-data'])) {
            $options['no-data'] = explode(',', $options['no-data']);
        }

        if (file_exists($destination)) {
            $dst = new Folder($destination);
            $dst->delete();
            $this->out(__d('system', 'Removing existing directory: {0}', $destination), 1, Shell::VERBOSE);
        } else {
            new Folder($destination, true);
            $this->out(__d('system', 'Creating directory: {0}', $destination), 1, Shell::VERBOSE);
        }

        $db = ConnectionManager::get('default');
        $db->connect();
        $schemaCollection = $db->schemaCollection();
        $tables = $schemaCollection->listTables();

        foreach ($tables as $table) {
            if (!empty($options['tables']) && !in_array($table, $options['tables'])) {
                $this->out(__d('system', 'Table "{0}" skipped', $table), 1, Shell::VERBOSE);
                continue;
            }

            $Table = TableRegistry::get($table);
            $Table->behaviors()->reset();
            $fields = [
                '_constraints' => [],
                '_indexes' => [],
                '_options' => (array)$Table->schema()->options(),
            ];
            $columns = $Table->schema()->columns();
            $records = [];
            $primaryKeys = [];

            foreach ($Table->schema()->indexes() as $indexName) {
                $index = $Table->schema()->index($indexName);
                if (!empty($index['columns'])) {
                    $fields['_indexes']["{$table}_{$indexName}_index"] = $index;
                }
            }

            foreach ($columns as $column) {
                $fields[$column] = $Table->schema()->column($column);
            }

            foreach ($Table->schema()->constraints() as $constraint) {
                $constraintName = in_array($constraint, $columns) ? Inflector::underscore("{$table}_{$constraint}") : $constraint;
                $fields['_constraints'][$constraintName] = $Table->schema()->constraint($constraint);
                if (isset($fields['_constraints']['primary']['columns'])) {
                    $primaryKeys = $fields['_constraints']['primary']['columns'];
                }
            }

            foreach ($fields as $column => $info) {
                if (isset($info['length']) &&
                    in_array($column, $primaryKeys) &&
                    isset($info['autoIncrement']) &&
                    $info['autoIncrement'] === true
                ) {
                    unset($fields[$column]['length']);
                }
            }

            // FIX: We need RAW data for time instead of Time Objects
            $originalTypes = [];
            foreach ($Table->schema()->columns() as $column) {
                $type = $Table->schema()->columnType($column);
                $originalTypes[$column] = $type;
                if (in_array($type, ['date', 'datetime', 'time'])) {
                    $Table->schema()->columnType($column, 'string');
                }
            }

            if ($options['mode'] === 'full') {
                foreach ($Table->find('all') as $row) {
                    $row = $row->toArray();
                    if ($this->params['no-id'] && isset($row['id'])) {
                        unset($row['id']);
                    }
                    $records[] = $row;
                }
            }

            $className = Inflector::camelize($table) . 'Fixture';
            if ($options['fixture'] && in_array($className, ['AcosFixture', 'UsersFixture'])) {
                $records = [];
            }

            // undo changes made by "FIX"
            foreach ($originalTypes as $column => $type) {
                $fields[$column]['type'] = $type;
            }

            if (empty($fields['_indexes'])) {
                unset($fields['_indexes']);
            }

            $fields = $this->_arrayToString($fields);
            $records = in_array($table, $options['no-data']) ? '[]' : $this->_arrayToString($records);

            $fixture = $this->_classFileHeader($className);
            $fixture .= "{\n";
            $fixture .= "\n";
            $fixture .= "    /**\n";
            $fixture .= "     * Table name.\n";
            $fixture .= "     *\n";
            $fixture .= "     * @var string\n";
            $fixture .= "     */\n";
            $fixture .= "    public \$table = '{$table}';\n";
            $fixture .= "\n";
            $fixture .= "    /**\n";
            $fixture .= "     * Table columns.\n";
            $fixture .= "     *\n";
            $fixture .= "     * @var array\n";
            $fixture .= "     */\n";
            $fixture .= "    public \$fields = {$fields};\n";
            $fixture .= "\n";
            $fixture .= "    /**\n";
            $fixture .= "     * Table records.\n";
            $fixture .= "     *\n";
            $fixture .= "     * @var array\n";
            $fixture .= "     */\n";
            $fixture .= "    public \$records = {$records};\n";
            $fixture .= "}\n";

            $file = new File(normalizePath("{$destination}/{$className}.php"), true);
            $file->write($fixture, 'w', true);
            $this->out(__d('system', 'Table "{0}" exported!', $table), 1, Shell::VERBOSE);
        }

        $this->out(__d('system', 'Database exported to: {0}', $destination));

        return true;
    }
480461
public function getSortedTableNames()
    {
        $tables = [
            strtolower($this->table_one),
            strtolower($this->table_two),
        ];

        sort($tables);

        return $tables;
    }
776808
protected function initsTable()
    {
        $this->sTable = [];

        for ($i = 0; $i < 256; $i++) {
            $this->sTable[$i] = \chr($i);
        }

        $this->tIdx = 258;
        $this->bitsToGet = 9;
    }
1296274
public function sortedTables(): array
    {
        $items = array_keys($this->tables);
        $this->states = $this->stack = [];

        foreach ($items as $item) {
            $this->sort($item, $this->dependencies[$item]);
        }

        return $this->stack;
    }
457887
public function tables()
    {
        $schema = $this->db->connection()
            ->getDoctrineConnection()
            ->getSchemaManager();

        $tables = $schema->listTableNames();

        foreach ($tables as $table) {
            $columns = $this->describer->describe($table);

            yield compact('table', 'columns');
        }
    }
263102
public function nulls() {
		$prefix = '';
		$tables = $this->_getTables($prefix);

		$todo = [];

		$db = $this->_getConnection();

		$this->out('Checking for tables that need updating:', 1, static::VERBOSE);
		foreach ($tables as $table) {
			// Structure
			$sql = 'DESCRIBE ' . $table['table_name'] . ';';
			$this->out('- ' . $sql, 1, static::VERBOSE);
			/** @var \Traversable $res */
			$res = $db->query($sql);
			$fields = (new Collection($res))->toArray();

			$fieldList = [];
			foreach ($fields as $field) {
				$name = $field['Field'];
				if ($name === 'id' || substr($name, -3) === '_id') {
					continue;
				}

				$type = $field['Type'];
				$null = $field['Null'];

				if (preg_match('/^tinyint\([\d]\)/', $type)) {
					if ($null === 'YES' || $field['Default'] !== null) {
						continue;
					}

					$todo[] = 'ALTER TABLE' . ' ' . $table['table_name'] . ' CHANGE `' . $name . '` `' . $name . '` ' . $type . ' NOT NULL DEFAULT \'0\';';

					continue;
				}

				if (!in_array($type, ['longtext', 'mediumtext', 'text']) && !preg_match('/^(varchar|char)\(/', $type)) {
					continue;
				}
				if ($type === 'varchar(36)' || $type === 'char(36)') {
					continue;
				}

				$fieldList[] = $field['Field'];

				if ($null === 'YES' || $field['Default'] !== null) {
					continue;
				}

				// We need to migrate sth
				if (!in_array($type, ['longtext', 'mediumtext', 'text'])) {
					$todo[] = 'ALTER TABLE' . ' ' . $table['table_name'] . ' CHANGE `' . $name . '` `' . $name . '` ' . $type . ' NOT NULL DEFAULT \'\';';
				} else {
					$todo[] = 'ALTER TABLE' . ' ' . $table['table_name'] . ' CHANGE `' . $name . '` `' . $name . '` ' . $type . ' DEFAULT NULL;';
				}
			}
		}

		if (!$todo) {
			$this->out('Nothing to do :)');
			return;
		}

		$this->out(count($todo) . ' tables/fields need updating.');
		if (!$this->param('dry-run')) {
			$continue = $this->in('Continue?', ['y', 'n'], 'y');
			if ($continue !== 'y') {
				$this->abort('Aborted!');
			}
		}
		$sql = implode(PHP_EOL, $todo);
		if (!$this->param('dry-run')) {
			$this->out($sql);
			return;
		}

		$db->query($sql);
		$this->out('Done :)');
	}
195083
protected function checkRequiredTables()
    {

        // check if relevant tables are present in the list
        foreach ([
                     config('pxlcms.tables.meta.modules'),
                     config('pxlcms.tables.meta.fields'),
                     config('pxlcms.tables.meta.field_options_choices'),
                     //config('pxlcms.tables.meta.groups'),
                     //config('pxlcms.tables.meta.sections'),
                     //config('pxlcms.tables.meta.field_types'),
                     //config('pxlcms.tables.meta.tabs'),
                     //config('pxlcms.tables.meta.users'),
                     //config('pxlcms.tables.meta.field_options_resizes'),

                     config('pxlcms.tables.languages'),
                     config('pxlcms.tables.categories'),
                     config('pxlcms.tables.files'),
                     config('pxlcms.tables.images'),
                     config('pxlcms.tables.references'),
                     config('pxlcms.tables.checkboxes'),
                     //config('pxlcms.tables.slugs'),

                 ] as $checkTable
        ) {
            if ( ! in_array($checkTable, $this->tables)) {

                throw new Exception("Could not find expected CMS table in database: '{$checkTable}'");
            }
        }
    }
826123
public function from($tables)
    {
        if (!is_array($tables)) {
            $tables = func_get_args();
        }

        $tables = $this->addTablePrefix($tables, false);
        $this->addStatement('tables', $tables);
        return $this;
    }
194029
public function getAllTables()
    {
        if (empty($this->_aTables)) {
            $tables = \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->getAll("show tables");

            foreach ($tables as $tableInfo) {
                if ($this->validateTableName($tableInfo[0])) {
                    $this->_aTables[] = $tableInfo[0];
                }
            }
        }

        return $this->_aTables;
    }