Returns the SQL strings for joining dependent tables.

@param array $attributes List of search attributes
@param string $prefix Search key prefix
@return array List of JOIN SQL strings
191393
private function _getJoins( array $attributes, $prefix )
	{
		$iface = 'MW_Common_Criteria_Attribute_Interface';
		$sep = $this->_getKeySeparator();
		$name = $prefix . $sep . 'id';

		if( isset( $attributes[$name] ) && $attributes[$name] instanceof $iface ) {
			return $attributes[$name]->getInternalDeps();
		}
		else if( isset( $attributes['id'] ) && $attributes['id'] instanceof $iface ) {
			return $attributes['id']->getInternalDeps();
		}

		return array();
	}
1022300
protected static function getClassMethodsByPrefix($prefix = null)
    {
        //
        $attribute = 'MethodsByPrefix:'.$prefix;

        if (!static::hasClassAttribute($attribute)) {
            $class = static::getClass();
            $allMethods = get_class_methods($class);
            $methods = [];

            if (count($allMethods) > 0) {
                foreach ($allMethods as $method) {
                    if (preg_match('/^'.$prefix.'/i', $method)) {
                        $methods[] = $method;
                    }
                }
            }
            asort($methods);

            static::setClassAttribute($attribute, $methods);
        }

        //
        return static::getClassAttribute($attribute);
    }
1134214
protected function prefixKeys($prefix, array $data)
	{
		$result = [];
		
		foreach($data as $k => $v)
		{
			$result[$prefix . $k] = $v;
		}
		
		return $result;
	}
988744
public function getKey(string $prefix = ''): string
    {
        $value = $this->getData();
        if (!is_array($value)) {
            $key = $value ?: '';
        } else {
            if (!empty($this->getAttributes())) {
                $flipped = array_flip($this->getAttributes());
                $value = array_intersect_key($value, $flipped);
            }

            $key = str_replace('=', '_', http_build_query($value, '', '_'));
        }

        return hash(self::ALGORITHM, $prefix.'_'.$key);
    }
1356258
public function foreignKeys($prefix = null) {
		$tables = $this->_getTables($prefix);

		$todo = [];

		$db = $this->_getConnection();
		foreach ($tables as $table) {
			// Structure
			$sql = 'DESCRIBE ' . $table['table_name'] . ';';
			$this->out('- ' . $sql, 1, static::VERBOSE);

			/** @var \Cake\Database\Statement\StatementDecorator $res */
			$res = $db->query($sql);
			$fields = new Collection($res);

			$fieldList = [];
			foreach ($fields as $field) {
				$name = $field['Field'];
				$type = $field['Type'];
				$null = $field['Null'];
				if (!preg_match('/\w+\_id$/', $name) || !preg_match('/^int\(1[10]\)|char\(36\)|varchar\(36\)/', $type)) {
					continue;
				}

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

				$isUuid = $type === 'char(36)' || $type === 'varchar(36)';
				if ($null === 'YES' && $field['Default'] === null) {
					continue;
				}

				if (!empty($field['Key']) && $field['Key'] === 'PRI') {
					continue;
				}
				if (!empty($field['Extra']) && $field['Extra'] === 'auto_increment') {
					continue;
				}

				// We need to migrate sth
				$todo[] = 'ALTER TABLE' . ' ' . $table['table_name'] . ' CHANGE `' . $name . '` `' . $name . '` ' . $type . ' NULL DEFAULT NULL;';
			}

			if (empty($fieldList)) {
				continue;
			}

			// Data
			$z = '0';
			$conditions = [];
			foreach ($fieldList as $fieldName) {
				$conditions[] = '`' . $fieldName . "` = '" . $z . "'";
			}
			$conditions = implode(' OR ', $conditions);

			$sql = 'SELECT COUNT(*) as count FROM ' . $table['table_name'] . ' WHERE ' . $conditions;
			$this->out('Checking for records that need updating:', 1, static::VERBOSE);
			$this->out(' - ' . $sql, 1, static::VERBOSE);
			/** @var \Cake\Database\Statement\StatementDecorator $res */
			$res = $db->query($sql);
			$res = (new Collection($res))->toArray();
			if (empty($res[0]['count'])) {
				continue;
			}

			$sets = [];
			foreach ($fieldList as $fieldName) {
				$todo[] = 'UPDATE ' . $table['table_name'] . ' SET ' . '`' . $fieldName . '` = NULL' . ' WHERE `' . $fieldName . '` = \'' . $z . '\';';
			}
		}

		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 (!empty($this->params['dry-run'])) {
			$this->out($sql);
			return;
		}

		// Execute
		$db->query($sql);
		$this->out('Done :)');
	}
119200
protected static function extract_record($record, $prefix) {
        $result = [];
        $prefixlength = strlen($prefix);
        foreach ($record as $key => $value) {
            if (strpos($key, $prefix) === 0) {
                $result[substr($key, $prefixlength)] = $value;
            }
        }
        return (object) $result;
    }
369883
private function buildQuery($table, $attributes = [])
    {
        if (class_exists($table)) {
            $query = $this->getQueryBuilderFromModel($table);
        } else {
            $query = $this->getQueryBuilderFromTable($table);
        }

        foreach ($attributes as $key => $value) {
            if (\is_array($value)) {
                call_user_func_array(array($query, "where"), $value);
            } elseif (is_null($value)) {
                $query->whereNull($key);
            } else {
                $query->where($key, $value);
            }
        }
        return $query;
    }
408975
protected function handleWheres(array $wheres, $prefix = true)
    {
        if (empty($wheres)) {
            return '';
        }

        $sql[] = $this->{$wheres[0]['type']}($wheres[0]);

        $count = count($wheres);

        for ($i = 1; $i < $count; $i++) {
            $sql[] = $wheres[$i]['separator'] . ' ' . $this->{$wheres[$i]['type']}($wheres[$i]);
        }

        return ($prefix ? ' WHERE ' : '') . implode(' ', $sql);
    }
963075
protected function getPhinxTableCollation($attributes, $table)
    {
        if (!empty($table['table']['table_collation'])) {
            $attributes[] = '\'collation\' => "' . addslashes($table['table']['table_collation']) . '"';
        } else {
            $attributes[] = '\'collation\' => "utf8_general_ci"';
        }

        return $attributes;
    }
1148070
protected function mergeDefaultAttributes(array $attributes)
    {
        if ($this->schema && !empty($this->schema->getDefaultValues())) {
            $attributes = array_merge($this->schema->getDefaultValues(), $attributes);
        }

        return $attributes;
    }
616603
private function getAttributesXpath(array $attributes)
    {
        $xpath = '';
        if (!empty($attributes)) {
            $parts = [];
            foreach ($attributes as $key => $value) {
                $parts[] = '@' . $key . '="' . $value . '"';
            }

            $xpath .= '[' . implode(' and ', $parts) . ']';
        }

        return $xpath;
    }
962287
public function updateSql(array $attributes)
    {
        $attrs = [];
        foreach ($attributes as $key => $value) {
            $attrs[$this->getModel()->convertToPrimaryKeyName($key)] = $value;
        }

        $sql = $this
            ->getQueryBuilder()
            ->update()
            ->table($this->getModel()->tableName())
            ->values($attrs)
            ->toSQL();

        return $sql;
    }
846564
public static function prefixArrayKeys($array, $prefix) {

        $prefixedArray = array();
        foreach ($array as $key => $value) {
            $prefixedArray [$prefix . $key] = $value;
        }

        return $prefixedArray;

    }
267474
public function get_tables($usecache=true) {
        if ($usecache and $this->tables !== null) {
            return $this->tables;
        }
        $this->tables = array();
        $prefix = str_replace('_', '\\_', $this->prefix);
        $sql = "SHOW TABLES LIKE '$prefix%'";
        $this->query_start($sql, null, SQL_QUERY_AUX);
        $result = $this->mysqli->query($sql);
        $this->query_end($result);
        $len = strlen($this->prefix);
        if ($result) {
            while ($arr = $result->fetch_assoc()) {
                $tablename = reset($arr);
                $tablename = substr($tablename, $len);
                $this->tables[$tablename] = $tablename;
            }
            $result->close();
        }

        // Add the currently available temptables
        $this->tables = array_merge($this->tables, $this->temptables->get_temptables());
        return $this->tables;
    }
32853
private static function extractAttributes(array $attributes = []): string
    {
        $extracted = [];
        if (\count($attributes) > 0) {
            foreach ($attributes as $name => $value) {
                if ($name != 'id' || ($name == 'id' && $value != '')) {
                    $extracted[] = sprintf(
                        '%s="%s"',
                        \strtolower($name),
                        \htmlspecialchars((string)$value, ENT_COMPAT | ENT_HTML5)
                    );
                }
            }
            return \sprintf(' %s', \implode(' ', $extracted));
        }
        return '';
    }
409267
protected function _getTables()
    {
        $prefix = \JFactory::getApplication()->get('dbprefix');
        $dbo    = \JFactory::getDbo();
        $tables = array();

        foreach (\JFactory::getDbo()->getTableList() as $table)
        {
            // Only check in tables with a prefix
            if (stripos($table, $prefix) === 0)
            {
                $columns = $dbo->getTableColumns($table);

                // Make sure that the table has the check in columns
                if (!isset($columns[$this->_user_column]) || !isset($columns[$this->_date_column])) {
                    continue;
                }

                // Check the column's types.
                if (stripos($columns[$this->_user_column], 'int') !== 0 || stripos($columns[$this->_date_column], 'date') !== 0) {
                    continue;
                }

                $query = $dbo->getQuery(true)
                             ->select('COUNT(*)')
                             ->from($dbo->quoteName($table))
                             ->where(sprintf('%s > 0', $this->_user_column));

                $dbo->setQuery($query);

                // Only include tables that need to be checked in
                if (!$dbo->execute() || !$dbo->loadResult()) {
                    continue;
                }

                $tables[] = str_replace($prefix, '', $table);
            }
        }

        return $tables;
    }
767481
protected function createQuery(array $attributes = null): Query
    {
        return Query::insert()->into(static::$tableName)
            ->set($attributes ?? $this->getFieldsValues());
    }