Przygotowuje nazwę pola do zapytania, konwertuje camelcase na podkreślenia
@param string $fieldName
@param string $forcedTableName
@return string
@throws OrmException
321602
protected final function _prepareField($fieldName, $forcedTableName = null)
    {
        //funkcja sortująca rand()
        if ($fieldName == 'RAND()') {
            return DbConnector::getAdapter()->prepareField('RAND()');
        }
        //nazwa tabeli
        $tableName = ($forcedTableName === null) ? $this->_tableName : $forcedTableName;
        //przygotowany prefix tabeli
        $tablePrefix = DbConnector::getAdapter()->prepareTable($tableName);
        //pole występuje w tabeli (jeden do jednego bez żadnych konwersji)
        if (DbConnector::fieldInTable($fieldName, $tableName)) {
            return $tablePrefix . '.' . DbConnector::getAdapter()->prepareField($fieldName);
        }
        //konwersja camelcase na podkreślenia
        return $tablePrefix . '.' . DbConnector::getAdapter()->prepareField(Convert::camelcaseToUnderscore($fieldName));
    }
783564
final private static function getColumnType($fieldName) {
		
		$db = Database::getInstance();
		$column = $db->describeColumn(static::TABLE_NAME, $fieldName);
		
		if (is_null($column)) {
			return NULL;
		}
		
		// split the column Type to recognize field type and length
		preg_match('#^([\w]+)(\([^\)]+\))? ?(unsigned)?#i', $column->Type, $matches);
		
		$field = new \stdClass();
		
		$field->name	= $fieldName;
		$field->type	= $matches[1];
		$field->unsigned= (isset($matches[3]));
		$field->nullable= 'YES' == $column->Null ? TRUE : FALSE;
		$field->key		= $column->Key;
		$field->default	= $column->Default;
		$field->extra	= $column->Extra;

		if (isset($matches[2])) {
			if (in_array($field->type, ['enum','set'])) {
				$field->length = explode("','", substr($matches[2], 2, -2));
			} else {
				$field->length = explode(",", substr($matches[2], 1, -1));
			}
		} else {
			$field->length = NULL;
		}
		
		return $field;
		
	}
356428
public static final function getTableStructure($tableName)
    {
        //pobranie struktury z obiektu (wcześniej zapisane)
        if (isset(self::$_tableStructure[$tableName])) {
            return self::$_tableStructure[$tableName];
        }
        //pobranie z cache
        $cacheKey = 'mmi-orm-structure-' . self::getAdapter()->getConfig()->name . '-' . $tableName;
        if (static::$_cache !== null && (null !== ($structure = static::$_cache->load($cacheKey)))) {
            return $structure;
        }
        //pobranie z adaptera
        $structure = static::getAdapter()->tableInfo($tableName);
        //zapis do bufora
        if (static::$_cache !== null) {
            static::$_cache->save($structure, $cacheKey, 0);
        }
        //zwrot i zapis do tablicy zapisanych struktur
        return self::$_tableStructure[$tableName] = $structure;
    }
1025137
public function orWhereIn(string $fieldName, $list)
    {
        return $this->where($fieldName, 'in', $list, LogicalOperator::OR);
    }
345548
public static function encodeGetRecord($tableName, $field, $value, $fields = array())
    {
        $select = "";
        $size = sizeof($fields);
        //Select fields to be returned
        if (sizeof($fields) > 0) {
            foreach ($fields as $i => $column) {
                $select .= " $column";
                if ($i != ($size - 1))
                    $select .= ",";
            }
        } else {
            $select = "*";
        }

        $query = "SELECT $select FROM $tableName WHERE $field = '$value';";
        return $query;
    }
280562
protected static function _updateQuery($tableName)
    {
        //prefixy nazw
        $namePrefix = self::_getNamePrefix($tableName);
        //nazwa klasy
        $className = $namePrefix . 'Query';
        //nazwa klasy pola
        $fieldClassName = $namePrefix . 'QueryField';
        //nazwa klasy złączenia
        $joinClassName = $namePrefix . 'QueryJoin';
        //nazwa rekordu
        $recordClassName = $namePrefix . 'Record';
        //ścieżka
        $path = self::_mkdirRecursive(self::_getPathPrefix($tableName)) . '/' . $className . '.php';
        //kod zapytania
        $queryCode = "{\n\n" . self::INDENT .
            'protected $_tableName = \'' .
            $tableName . '\';' .
            "\n\n}";
        //wczytanie istniejącego rekordu
        if (file_exists($path)) {
            $queryCode = file_get_contents($path);
        }
        //odczyt struktury
        $structure = DbConnector::getTableStructure($tableName);
        //pusta, lub błędna struktura
        if (empty($structure)) {
            throw new OrmException('\Mmi\Orm\Builder: no table found, or table invalid: ' . $tableName);
        }

        $methods = '';
        //budowanie komentarzy do metod
        foreach ($structure as $fieldName => $fieldDetails) {
            $fieldName = ucfirst(Convert::underscoreToCamelcase($fieldName));
            //metody where... np. whereActive()
            $methods .= ' * @method QueryHelper\\' . $fieldClassName . ' where' . $fieldName . '()' . "\n";
            //metody andField... np. andFieldActive()
            $methods .= ' * @method QueryHelper\\' . $fieldClassName . ' andField' . $fieldName . '()' . "\n";
            //orField
            $methods .= ' * @method QueryHelper\\' . $fieldClassName . ' orField' . $fieldName . '()' . "\n";
            //orderAsc
            $methods .= ' * @method ' . $className . ' orderAsc' . $fieldName . '()' . "\n";
            //orderDesc
            $methods .= ' * @method ' . $className . ' orderDesc' . $fieldName . '()' . "\n";
            //groupBy
            $methods .= ' * @method ' . $className . ' groupBy' . $fieldName . '()' . "\n";
        }
        $queryHead = '<?php' . "\n\n" .
            'namespace ' . self::_getNamespace($tableName) . ";\n\n" .
            '//<editor-fold defaultstate="collapsed" desc="' . $className . '">' . "\n" .
            '/**' . "\n" .
            ' * @method ' . $className . ' limit($limit = null)' . "\n" .
            ' * @method ' . $className . ' offset($offset = null)' . "\n" .
            ' * @method ' . $className . ' orderAsc($fieldName, $tableName = null)' . "\n" .
            ' * @method ' . $className . ' orderDesc($fieldName, $tableName = null)' . "\n" .
            ' * @method ' . $className . ' andQuery(\Mmi\Orm\Query $query)' . "\n" .
            ' * @method ' . $className . ' whereQuery(\Mmi\Orm\Query $query)' . "\n" .
            ' * @method ' . $className . ' orQuery(\Mmi\Orm\Query $query)' . "\n" .
            ' * @method ' . $className . ' resetOrder()' . "\n" .
            ' * @method ' . $className . ' resetWhere()' . "\n" .
            $methods .
            ' * @method QueryHelper\\' . $fieldClassName . ' andField($fieldName, $tableName = null)' . "\n" .
            ' * @method QueryHelper\\' . $fieldClassName . ' where($fieldName, $tableName = null)' . "\n" .
            ' * @method QueryHelper\\' . $fieldClassName . ' orField($fieldName, $tableName = null)' . "\n" .
            ' * @method QueryHelper\\' . $joinClassName . ' join($tableName, $targetTableName = null, $alias = null)' . "\n" .
            ' * @method QueryHelper\\' . $joinClassName . ' joinLeft($tableName, $targetTableName = null, $alias = null)' . "\n" .
            ' * @method ' . $recordClassName . '[] find()' . "\n" .
            ' * @method ' . $recordClassName . ' findFirst()' . "\n" .
            ' * @method ' . $recordClassName . ' findPk($value)' . "\n" .
            ' */' . "\n" . '//</editor-fold>' . "\n" . 'class ' . $className . ' extends \Mmi\Orm\Query';
        $queryCode = $queryHead . "\n" . substr($queryCode, strpos($queryCode, '{'));
        file_put_contents($path, $queryCode);
    }
997876
private function toCamelCase($fieldname)
    {
        $words = str_replace('_', ' ', $fieldname);
        $words = ucwords($words);
        $pascalCased = str_replace(' ', '', $words);

        return lcfirst($pascalCased);
    }
299566
protected final function _prepareOrder($fieldName, $tableName = null, $asc = true)
    {
        //jeśli pusty order - dodawanie ORDER BY na początku
        if (!$this->_compile->order) {
            $this->_compile->order = 'ORDER BY ';
        } else {
            $this->_compile->order .= ', ';
        }
        $this->_compile->order .= $this->_prepareField($fieldName, $tableName) . ' ' . ($asc ? 'ASC' : 'DESC');
        return $this;
    }
612737
public function getUniqueIndexNames ($table_name, $forced_obtain = false) {
		if (!isset(array_flip($this->getTables($forced_obtain))[$table_name])) {
			throw CoreException::RaiseSystemError('存在しないテーブルを指定されました。table_name:%s', [$table_name]);
		}
		if ($forced_obtain || !isset($this->_uniqueIndexNames[$table_name])) {
			$this->_updateUniqueIndexNames($table_name);
		}
		return $this->_uniqueIndexNames[$table_name];
	}
1119564
final public static function isNullable($fieldName) {
		
		$db = Database::getInstance();
		$column = $db->describeColumn(static::TABLE_NAME, $fieldName);
		
		if (is_null($column)) {
			return NULL;
		}
		
		return ('YES'==$column->Null ? TRUE : FALSE);
		
	}
379558
private function writeChangedTable( $tableName, ezcDbSchemaTableDiff $changedTable )
    {
        $this->writer->startElement( 'table' );
        $this->writer->startElement( 'name' );
        $this->writer->text( $tableName );
        $this->writer->endElement();
        $this->writer->flush();

        // added fields 
        $this->writer->startElement( 'added-fields' );
        $this->writer->flush();
        foreach ( $changedTable->addedFields as $fieldName => $field )
        {
            $this->writer->startElement( 'field' );
            $this->writeField( $fieldName, $field );

            $this->writer->endElement();
            $this->writer->flush();
        }
        $this->writer->endElement();
        $this->writer->flush();

        // changed fields 
        $this->writer->startElement( 'changed-fields' );
        $this->writer->flush();
        foreach ( $changedTable->changedFields as $fieldName => $field )
        {
            $this->writer->startElement( 'field' );
            $this->writeField( $fieldName, $field );

            $this->writer->endElement();
            $this->writer->flush();
        }
        $this->writer->endElement();
        $this->writer->flush();

        // Removed fields
        $this->writer->startElement( 'removed-fields' );
        $this->writer->flush();
        foreach ( $changedTable->removedFields as $fieldName => $fieldStatus )
        {
            $this->writer->startElement( 'field' );
            $this->writer->startElement( 'name' );
            $this->writer->text( $fieldName );
            $this->writer->endElement();
            $this->writer->startElement( 'removed' );
            $this->writer->text( $fieldStatus ? 'true' : 'false' );
            $this->writer->endElement();
            $this->writer->endElement();
            $this->writer->flush();
        }
        $this->writer->endElement();
        $this->writer->flush();

        // added indexes 
        $this->writer->startElement( 'added-indexes' );
        $this->writer->flush();
        foreach ( $changedTable->addedIndexes as $indexName => $index )
        {
            $this->writer->startElement( 'index' );
            $this->writeIndex( $indexName, $index );

            $this->writer->endElement();
            $this->writer->flush();
        }
        $this->writer->endElement();
        $this->writer->flush();

        // changed indexes 
        $this->writer->startElement( 'changed-indexes' );
        $this->writer->flush();
        foreach ( $changedTable->changedIndexes as $indexName => $index )
        {
            $this->writer->startElement( 'index' );
            $this->writeIndex( $indexName, $index );

            $this->writer->endElement();
            $this->writer->flush();
        }
        $this->writer->endElement();
        $this->writer->flush();

        // Removed indexes
        $this->writer->startElement( 'removed-indexes' );
        $this->writer->flush();
        foreach ( $changedTable->removedIndexes as $indexName => $indexStatus )
        {
            $this->writer->startElement( 'index' );
            $this->writer->startElement( 'name' );
            $this->writer->text( $indexName );
            $this->writer->endElement();
            $this->writer->startElement( 'removed' );
            $this->writer->text( $indexStatus ? 'true' : 'false' );
            $this->writer->endElement();
            $this->writer->endElement();
            $this->writer->flush();
        }

        $this->writer->endElement();
        $this->writer->flush();

        $this->writer->endElement();
    }
1036119
static protected function getMMTableName($ftable, $fkey, $ptable, $pkey, $fConf=null) {
		if ($fConf) {
			list($fclass, $pfkey) = $fConf;
			$self = get_called_class();
			// check for a matching config
			if ($pfkey != $pkey)
				trigger_error(sprintf(self::E_MM_REL_FIELD,
					$fclass.'.'.$pfkey, $self.'.'.$pkey),E_USER_ERROR);
		}
		$mmTable = array($ftable.'__'.$fkey, $ptable.'__'.$pkey);
		natcasesort($mmTable);
		// shortcut for self-referencing mm tables
		if ($mmTable[0] == $mmTable[1] ||
			($fConf && isset($fConf['isSelf']) && $fConf['isSelf']==true))
			return array_shift($mmTable);
		$return = strtolower(str_replace('\\', '_', implode('_mm_', $mmTable)));
		return $return;
	}
1110453
public function buildQuery($tablename)
    {
        $pluralTableName = self::pluralize($tablename);
        $query = "CREATE TABLE IF NOT EXISTS {$pluralTableName} (".PHP_EOL;

        $callback = function($fieldName) use (&$query)
        {
            $fields = explode(" ", $fieldName);
         
            $constrain = $fields[0];
            if(count($fields) == 2)
            {
                $query .= $this->$constrain($fields[1], 20) .", ".PHP_EOL;
            }else
            {
                    $query .= $this->$constrain($fields[1], $fields[2]) .", ".PHP_EOL;
            }
        };
        array_walk($this->fieldDescription, $callback);
        $query .= ');)';

        return $query;
    }
991551
public function AllowEditOfField($sFieldName)
    {
        $aFieldsEditable = $this->GetChangableFieldNames();
        $sFieldName = str_replace('`', '', $sFieldName);

        return in_array($sFieldName, $aFieldsEditable);
    }
215323
private function getAlteredQueryNode($fieldName, array $values)
    {
        $newNode = new OrNode();
        $defaultLanguageFieldName = $fieldName.'.'.$this->intUtils->getDefaultLanguage();

        foreach ($values as $singleValue) {
            $newNode->addQuery($this->getEqNode($fieldName, $singleValue));
            // search default language field (as new structure only has 'en' set after creation and no save)
            $newNode->addQuery(
                $this->getEqNode(
                    $defaultLanguageFieldName,
                    $singleValue
                )
            );
        }

        // add default match
        $newNode->addQuery($this->getEqNode($this->node->getField(), $this->getNodeValue()));

        if (!$this->nodeFieldNameHasLanguage()) {
            // if no language, we add it to the query to default node for default language
            $newNode->addQuery(
                $this->getEqNode(
                    $defaultLanguageFieldName,
                    $this->getNodeValue()
                )
            );
        }

        return $newNode;
    }
938133
public static function encodeCreateTable($tableName, $fields)
    {
        $query = "CREATE TABLE IF NOT EXISTS $tableName (";
        $keys = array_keys($fields);
        $size = sizeof($keys);

        foreach ($keys as $index => $field) {
            $query .= " $field";
            $attribs = $fields[$field];
            foreach ($attribs as $i => $attrib) {
                if ($i == 1)
                    $query .= ($attrib == "0" ? "" : "($attrib)");
                else
                    $query .= " $attrib";
            }
            if ($index != ($size - 1))
                $query .= " ,";
        }

        $query .= ") ENGINE=InnoDB DEFAULT CHARSET=latin1;";
        return $query;
    }
357965
private function getFieldNameForColumn($tableName, $columnName, $fk = false)
    {
        if (isset($this->fieldNamesForColumns[$tableName], $this->fieldNamesForColumns[$tableName][$columnName])) {
            return $this->fieldNamesForColumns[$tableName][$columnName];
        }

        $columnName = strtolower($columnName);

        // Replace _id if it is a foreignkey column
        if ($fk) {
            $columnName = str_replace('_id', '', $columnName);
        }

        return Inflector::camelize($columnName);
    }