Encodes get record statement
@param string $tableName
@param string $field field to match
@param string $value value to match with field
@param array $fields columns to be returned
@return string executable SQL statement
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;
    }
1224592
public static function getFieldKey($fieldName, $fieldId)
    {
        if (isset(get_field_objects($fieldId)[$fieldName]['key'])) {
            return get_field_objects($fieldId)[$fieldName]['key'];
        }

        return false;
    }
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;
    }
162780
function select($table, $fields, $where)
	{
		$query = 'SELECT '.$fields.' FROM '.$table.' '.$this->args_compile($where);
//		$query = str_replace('`', '"', $query);
		return $this->get($query);
	}
575801
private function FieldCondition($field, $value)
        {
            $tbl = $this->Table();
            $mapper = $this->FieldMapper($field);
            $dbVal = $mapper->ToDBString($value);
            
            $sql = $this->SqlBuilder();
            
            if ($dbVal === null)
                return $sql->IsNull($tbl->Field($field));
            else
                return $sql->Equals($tbl->Field($field), $sql->Value($dbVal));
        }
1238693
public function addTablePrefix($values, $tableFieldMix = true)
    {
        if (is_null($this->tablePrefix)) {
            return $values;
        }

        // $value will be an array and we will add prefix to all table names

        // If supplied value is not an array then make it one
        $single = false;
        if (!is_array($values)) {
            $values = array($values);
            // We had single value, so should return a single value
            $single = true;
        }

        $return = array();

        foreach ($values as $key => $value) {
            // It's a raw query, just add it to our return array and continue next
            if ($value instanceof Raw || $value instanceof \Closure) {
                $return[$key] = $value;
                continue;
            }

            // If key is not integer, it is likely a alias mapping,
            // so we need to change prefix target
            $target = &$value;
            if (!is_int($key)) {
                $target = &$key;
            }

            if (!$tableFieldMix || ($tableFieldMix && strpos($target, '.') !== false)) {
                $target = $this->tablePrefix . $target;
            }

            $return[$key] = $value;
        }

        // If we had single value then we should return a single value (end value of the array)
        return $single ? end($return) : $return;
    }
568484
final public function setRowFieldValue($field, $value)
    {

        //If value exists;
        if (array_key_exists($field, $this->schema)) {
            $this->schema[$field]->Value = $value;
            return true;
        }
        return false;
    }
754406
public function getFieldInformation($tableName, $fieldName)
    {
        $columns = $this->database->metaColumns($tableName);

        foreach($columns as $column) {
            if ($column->name === $fieldName) {

                return $column;
            }
        }

        return null;
    }
475339
public function getFieldUses($tablename, $fieldname) {

        $uses = array();

        // Check if any key in the table is using it
        $table = $this->getTable($tablename);
        if ($keys = $table->getKeys()) {
            foreach ($keys as $key) {
                if (in_array($fieldname, $key->getFields()) ||
                    in_array($fieldname, $key->getRefFields())) {
                        $uses[] = 'table ' . $table->getName() . ' key ' . $key->getName();
                }
            }
        }
        // Check if any index in the table is using it
        $table = $this->getTable($tablename);
        if ($indexes = $table->getIndexes()) {
            foreach ($indexes as $index) {
                if (in_array($fieldname, $index->getFields())) {
                    $uses[] = 'table ' . $table->getName() . ' index ' . $index->getName();
                }
            }
        }
        // Check if some foreign key in the whole structure is using it
        // By comparing the reftable and refields with the field)
        if ($this->tables) {
            foreach ($this->tables as $table) {
                $keys = $table->getKeys();
                if ($keys) {
                    foreach ($keys as $key) {
                        if ($key->getType() == XMLDB_KEY_FOREIGN) {
                            if ($tablename == $key->getRefTable()) {
                                $reffieds = $key->getRefFields();
                                if (in_array($fieldname, $key->getRefFields())) {
                                    $uses[] = 'table ' . $table->getName() . ' key ' . $key->getName();
                                }
                            }
                        }
                    }
                }
            }
        }

        // Return result
        if (!empty($uses)) {
            return $uses;
        } else {
            return false;
        }
    }
605877
public function cuSelectOneDataSet($tableName, $fieldName, $fieldValue)
    {

        $where         = " $fieldName='$fieldValue' ";
        $dataSetsArray = $this->cuSelectAsArray($tableName, $where);

        $dataSetArray = null;
        if (array_key_exists(0, $dataSetsArray)) {
            $dataSetArray = $dataSetsArray[0];
        }

        return $dataSetArray;
    }
334004
public function get($value, $field = '*', $name = 'id')
    {
        $map = array(
            $name => $value
        );
        return $this->where($map)
            ->field($field)
            ->find();
    }
122258
public function selectBy($field, $value, $table = null)
	{
		if(null === $table)
		{
			$table = $this->tableName();
		}
		return $this->where(array((false === $table ? '' : ($table . '.')) . $field=>$value))->select();
	}
671703
public function getValue($value = '', $field = 'id', $fieldOutput = '')
    {
        if (is_array($value) && count($value) > 0) {
            foreach ($value as $f => $v) {
                if (is_array($v)) {
                    $this->db->where($f, $v, self::OPERATOR_IS_IN);
                } else {
                    $this->db->where($f, $v, self::OPERATOR_EQUAL_TO);
                }
            }
        } else {
            $this->db->where($field, $value, self::OPERATOR_EQUAL_TO);
        }
        $result = $this->db->getOne($this->table, $fieldOutput);
        $this->debug->debug(__FUNCTION__, 'GET Result => ' . json_encode($result));
        if (isset($result->$fieldOutput)) {
            return $result->$fieldOutput;
        } else {
            return NULL;
        }
    }
606630
public function findByField($field, $value = null, $columns = ['*'])
    {
        return parent::findByField(
            $this->getColumnName($field),
            $value,
            $this->getColumnsNames($columns)
        );
    }
1362144
public function valueExists($field, $value = null)
    {
        $record = new static($this->table, $this->keys, $this->mapper);

        if ($value === null) {
            $value = $this->$field;
        }

        try {
            $record->load([$field => $value]);
        } catch (NoResultException $e) {
            return false;
        }

        if ($record->$field != $value) {
            return false;
        }

        // check record keys same as self
        $same = [];

        foreach ($this->keys as $key) {
            $same[] = ($record->$key == $this->$key);
        }

        // Key not same, means same value exists in other record.
        if (in_array(false, $same, true)) {
            return true;
        }

        return false;
    }
693331
public function getValue($value = '', $field = 'id', $fieldOutput = '')
    {
        if (!is_array($fieldOutput)) {
            $fieldOutput = [$fieldOutput];
        }
        $db = $this->db->select($fieldOutput)->from($this->table);
        if (is_array($value) && count($value) > 0) {
            foreach ($value as $column => $column_value) {
                if (is_array($column_value)) {
                    $db->whereIn($column, $column_value);
                } else {
                    $db->where($column, self::OPERATOR_EQUAL_TO, $column_value);
                }
            }
        } else {
            $db->where($field, self::OPERATOR_EQUAL_TO, $value);
        }
        $result = $db->execute()->fetch();

        $this->debug->debug(__FUNCTION__, 'GET Result => ' . json_encode($result));
        if (isset($result->$fieldOutput)) {
            return $result->$fieldOutput;
        } else {
            return NULL;
        }
    }
1172644
public static function insert(string $table, array $fields, array $values = null): string
    {
        // Compare $fields and $values arrays for equality
        if (isset($values)) {
            if (count($values) !== count($fields)) {
                echo "Fields count is not equal to Values count!" . PHP_EOL;
                exit;
            }
        }

        // Generate SQL statement
        $sql  = "INSERT INTO `$table` (";
        $sql .= "`" . implode('`, `', $fields) . "`";
        $sql .= ") VALUES (";

        $sql_fields = '';
        if (!isset($values)) {
            // If $value array  is not set, generate prepared SQL statement
            foreach ($fields as $field) {
                $sql_fields .= ":$field, ";
            }
        } else {
            // Otherwise use $values fields' values
            foreach ($values as $field) {
                $sql_fields .= "'$field', ";
            }
        }
        $sql .= rtrim($sql_fields, ' ,') . ")";
        return $sql;
    }