Build SET for INSERT

@param  string $prefix
@param  array $settings
@return string
@access protected
961732
protected function buildInsertSet(
        /*# string */ $prefix,
        array $settings
    )/*# : string */ {
        if (empty($this->set_data)) {
            return '';
        }

        $cols = [];
        foreach (array_keys($this->set_col) as $col) {
            $cols[] = $this->quote($col, $settings);
        }
        return $settings['seperator'] . '(' . join(', ', $cols) . ')';
    }
1047558
public function getStatement(array $settings = [])/*# : string */
    {
        // combine settings
        $settings = $this->combineSettings($settings);

        // statements
        $sql = [];

        // build previous statement
        if ($this->hasPrevious()) {
            $sql[] = $this->getPrevious()->getStatement($settings);
        }

        // build current sql
        $sql[] = $this->buildSql($settings);

        // replace with ?, :name or real values
        return $this->bindValues(join($settings['seperator'], $sql), $settings);
    }
699527
protected function buildValues(
        /*# string */ $prefix,
        array $settings
    )/*# : string */ {
        $rows = [];
        $cols = array_keys($this->set_col);
        foreach ($this->set_data as $row) {
            $values = [];
            foreach ($cols as $col) {
                $values[] = isset($row[$col]) ?
                    $this->processValue($row[$col], $settings) :
                    $this->nullOrDefault($settings);
            }
            $rows[] = '(' . join(', ', $values) . ')';
        }
        return $this->joinClause($prefix, ',', $rows, $settings);
    }
857418
protected function validateTopic(array $settings, array $rules, $prefix = '') {
        $errors = [];

        foreach ($rules as $rule) {
            if (strlen($prefix) > 0) {
                $key = $prefix . '.' . $rule['key'];
            } else {
                $key = $rule['key'];
            }

            if ($rule['required'] &&
                !array_key_exists($rule['key'], $settings)) {
                $errors[] = sprintf(
                    'Missing configuration setting "%s"',
                    $key
                );
                continue;
            } elseif ($rule['required'] === false &&
                !array_key_exists($rule['key'], $settings)) {
                continue;
            }

            $value = $settings[$rule['key']];

            switch ($rule['type']) {
                case 'object':
                    if (!is_array($value)) {
                        $errors[] = sprintf(
                            'Configuration setting "%s" is not an object',
                            $key
                        );
                    }

                    $errors = $errors + $this->validateTopic($value, $rule['nodes'], $key);
                    break;
                case 'array':
                    if (!is_array($value)) {
                        $errors[] = sprintf(
                            'Configuration setting "%s" is not an array',
                            $key
                        );
                    }

                    if (array_key_exists('minCount', $rule)) {
                        if (count($value) < $rule['minCount']) {
                            $errors[] = sprintf(
                                'Configuration setting "%s" has too few elements',
                                $key
                            );
                        }
                    }

                    if (array_key_exists('items', $rule)) {
                        foreach ($value as $item) {
                            switch ($rule['items']) {
                                case 'string':
                                    if (!is_string($item)) {
                                        $errors[] = sprintf(
                                            'Configuration setting "%s" contains a non string value',
                                            $key
                                        );
                                    }

                                    if (array_key_exists('minLength', $rule)) {
                                        if (strlen($item) < $rule['minLength']) {
                                            $errors[] = sprintf(
                                                'Configuration setting "%s" has a too short string "%s". ' .
                                                'Minimum length is %s character(s).',
                                                $key,
                                                $item,
                                                $rule['minLength']
                                            );
                                        }
                                    }
                                    break;
                                case 'boolean':
                                    if (!is_bool($item)) {
                                        $errors[] = sprintf(
                                            'Configuration setting "%s" contains a non boolean value',
                                            $key
                                        );
                                    }
                                    break;
                                case 'integer':
                                    if (!is_int($item)) {
                                        $errors[] = sprintf(
                                            'Configuration setting "%s" contains a non integer value',
                                            $key
                                        );
                                    }
                                    break;
                                default:
                                    throw new Exception(sprintf(
                                        'Unknown value "%s" for "items"',
                                        $rule['items']
                                    ), ExitApp::RUNTIME_ERROR);
                            }
                        }
                    }

                    if (array_key_exists('values', $rule)) {
                        foreach ($value as $item) {
                            if (!in_array($item, $rule['values'])) {
                                $errors[] = sprintf(
                                    'Configuration setting "%s" has an unknown value',
                                    $key
                                );
                            }
                        }
                    }
                    break;
                case 'string':
                    if (!is_string($value)) {
                        $errors[] = sprintf(
                            'Configuration setting "%s" is not a string',
                            $key
                        );
                    }

                    if (array_key_exists('minLength', $rule)) {
                        if (strlen($value) < $rule['minLength']) {
                            $errors[] = sprintf(
                                'Configuration setting "%s" is too short. Minimum length is %s character(s).',
                                $key,
                                $rule['minLength']
                            );
                        }
                    }

                    if (array_key_exists('values', $rule)) {
                        if (!in_array($value, $rule['values'])) {
                            $errors[] = sprintf(
                                'Configuration setting "%s" is unknown',
                                $key
                            );
                        }
                    }
                    break;
                case 'integer':
                    if (!is_int($value)) {
                        $errors[] = sprintf(
                            'Configuration setting "%s" is not an integer',
                            $key
                        );
                    }

                    if (array_key_exists('gt', $rule)) {
                        if ($value <= $rule['gt']) {
                            $errors[] = sprintf(
                                'Configuration setting "%s" is not greater than %s',
                                $key,
                                $rule['gt']
                            );
                        }
                    }

                    if (array_key_exists('ge', $rule)) {
                        if ($value < $rule['ge']) {
                            $errors[] = sprintf(
                                'Configuration setting "%s" is not greater or equal %s',
                                $key,
                                $rule['ge']
                            );
                        }
                    }

                    if (array_key_exists('lt', $rule)) {
                        if ($value >= $rule['lt']) {
                            $errors[] = sprintf(
                                'Configuration setting "%s" is not less than %s',
                                $key,
                                $rule['lt']
                            );
                        }
                    }

                    if (array_key_exists('le', $rule)) {
                        if ($value > $rule['le']) {
                            $errors[] = sprintf(
                                'Configuration setting "%s" is not less or equal %s',
                                $key,
                                $rule['le']
                            );
                        }
                    }
                    break;
                case 'boolean':
                    if (!is_bool($value)) {
                        $errors[] = sprintf(
                            'Configuration setting "%s" is not a boolean',
                            $key
                        );
                    }
                    break;
                case 'mixed':
                    if (array_key_exists('values', $rule)) {
                        if (!in_array($value, $rule['values'])) {
                            $errors[] = sprintf(
                                'Configuration setting "%s" is unknown',
                                $key
                            );
                        }
                    }
                    break;
                default:
                    throw new Exception(sprintf(
                        'Unknown type "%s" in schema',
                        $rule['type']
                    ), ExitApp::RUNTIME_ERROR);
            }
        }

        return $errors;
    }
1052148
public function insertRow($table, array $settings, $bind = true)
    {
        //build insert query
        $query = $this->getInsertQuery($table);

        //foreach settings
        foreach ($settings as $key => $value) {
            //if value is not a vulnerability
            if (is_null($value) || is_bool($value)) {
                //just add it to the query
                $query->set($key, $value);
                continue;
            }

            //if bind is true or is an array and we want to bind it
            if ($bind === true || (is_array($bind) && in_array($key, $bind))) {
                //bind the value
                $value = $this->bind($value);
            }

            //add it to the query
            $query->set($key, $value);
        }

        //run the query
        $this->query($query, $this->getBinds());

        return $this;
    }
599397
public function insertRow($table, array $settings, $bind = true)
    {
        //argument test
        Argument::i()
            //Argument 1 must be a string
            ->test(1, 'string')
            //Argument 3 must be an array or bool
            ->test(3, 'array', 'bool');
        
        //build insert query
        $query = $this->insert($table);
        
        //foreach settings
        foreach ($settings as $key => $value) {
            //if value is not a vulnerability
            if (is_null($value) || is_bool($value)) {
                //just add it to the query
                $query->set($key, $value);
                continue;
            }
            
            //if bind is true or is an array and we want to bind it
            if ($bind === true || (is_array($bind) && in_array($key, $bind))) {
                //bind the value
                $value = $this->bind($value);
            }
            
            //add it to the query
            $query->set($key, $value);
        }
        
        //run the query
        $this->query($query, $this->getBinds());
        
        //event trigger
        $this->trigger('sql-insert', $table, $settings);
        
        return $this;
    }
495743
public function add($methods, $route, $settings, $callback = null)
    {
        if($this->cacheLoaded) {
            return true;
        }

        if (is_null($callback)) {
            $callback = $settings;
            $settings = null;
        }

        if (strstr($methods, '|')) {
            foreach (array_unique(explode('|', $methods)) as $method) {
                if ($method != '') {
                    call_user_func_array([$this, strtolower($method)], [$route, $settings, $callback]);
                }
            }
        } else {
            call_user_func_array([$this, strtolower($methods)], [$route, $settings, $callback]);
        }

        return true;
    }
681864
public function setPrefix($prefix, $field = null)
    {
        $param = $this->buildParam('facet.prefix', $field);
        return $this->set($param, $prefix);
    }
247570
protected function bindValues(/*# string */ $sql, array $settings)/*# : string */
    {
        // init bindings
        $this->bindings = [];

        // bind values
        return $this->getBuilder()->getParameter()
            ->bindValues($sql, $this->bindings, $settings);
    }
691925
protected function insertRecordSets(array &$sets)
    {
        $timestamp = $this->unixTimestamp === true ? strtotime(date('Y-m-d H:i:s')) : date('Y-m-d H:i:s');

        if(is_null($this->recordUser)) {
            if(globals()->offsetExists('account')) {
                $this->setRecordUser(globals()->account->id);
            }
        }

        if ( ! isset($sets[ 'record_status' ])) {
            $sets[ 'record_status' ] = $this->recordStatus;
        }

        if (empty($this->primaryKeys)) {
            $primaryKey = isset($this->primaryKey) ? $this->primaryKey : 'id';

            if (isset($sets[ $primaryKey ])) {
                if (empty($sets[ $primaryKey ])) {
                    unset($sets[ $primaryKey ]);
                }
            }

            if (empty($sets[ $primaryKey ])) {
                if ( ! isset($sets[ 'record_create_user' ])) {
                    $sets[ 'record_create_user' ] = $this->recordUser;
                }

                if ( ! isset($sets[ 'record_create_timestamp' ])) {
                    $sets[ 'record_create_timestamp' ] = $timestamp;
                } elseif ($this->unixTimestamp) {
                    $sets[ 'record_create_timestamp' ] = strtotime($sets[ 'record_create_timestamp' ]);
                }
            }
        } else {
            foreach ($this->primaryKeys as $primaryKey) {
                if (empty($sets[ $primaryKey ])) {
                    if ( ! isset($sets[ 'record_create_user' ])) {
                        $sets[ 'record_create_user' ] = $this->recordUser;
                    }

                    if ( ! isset($sets[ 'record_create_timestamp' ])) {
                        $sets[ 'record_create_timestamp' ] = $timestamp;
                    } elseif ($this->unixTimestamp) {
                        $sets[ 'record_create_timestamp' ] = strtotime($sets[ 'record_create_timestamp' ]);
                    }
                }
            }
        }

        if ( ! isset($sets[ 'record_update_user' ])) {
            $sets[ 'record_update_user' ] = $this->recordUser;
        }

        if ( ! isset($sets[ 'record_update_timestamp' ])) {
            $sets[ 'record_update_timestamp' ] = $timestamp;
        } elseif ($this->unixTimestamp) {
            $sets[ 'record_update_timestamp' ] = strtotime($sets[ 'record_update_timestamp' ]);
        }

        if ( ! isset($sets[ 'record_ordering' ]) && $this->recordOrdering === true) {
            $sets[ 'record_ordering' ] = $this->getRecordOrdering();
        }
    }
151206
protected function createOutput(Settings $settings) : string
    {
        return StrFormat::format(
            '{{scheme}}{{domain}}{{path}}{{query}}{{fragment}}',
            $this->parseUrlComponents($settings),
            new StrSettings([ 'removeUnparsed' => true ])
        );
    }
1278169
public function insertRows($table, array $settings, $bind = true)
    {
        //argument test
        Argument::i()
            //Argument 1 must be a string
            ->test(1, 'string')
            //Argument 3 must be an array or bool
            ->test(3, 'array', 'bool');
        
        //this is an array of arrays
        foreach ($settings as $index => $setting) {
            //SQLite no available multi insert
            //there's work arounds, but no performance gain
            $this->insertRow($table, $setting, $bind);
        }
        
        return $this;
    }
1183640
protected function buildLimit(
        /*# string */ $prefix,
        array $settings
    )/*# : string */ {
        $result = [];
        $clause = &$this->getClause('LIMIT');
        if (!empty($clause)) {
            $res = [];
            if ($clause[0]) {
                $res[] = $clause[0];
            }
            if ($clause[1]) {
                $res[] = 'OFFSET ' . $clause[1];
            }
            $result[] = join(' ', $res);
        }
        return $this->joinClause($prefix, ' ', $result, $settings);
    }
330580
public function createSection($settings = null) {
		$sectionCount = $this->_countSections() + 1;
		
		$section = new PHPWord_Section($sectionCount, $settings);
		$this->_sectionCollection[] = $section;
		return $section;
	}
913354
private function initializeDatabase(array $settings)
    {
        if (!isset($settings['dsn']) || !$settings['dsn']) {
            $settings['charset'] = isset($settings['charset']) ? $settings['charset'] : 'utf8';
            $settings['dsn'] = sprintf(
                '%s:host=%s;dbname=%s;charset=%s',
                $settings['driver'],
                $settings['host'],
                $settings['name'],
                $settings['charset']
            );
        }

        return $settings;
    }
1007903
private function setSettings($settings)
    {
        if ($settings) {
            foreach ($this->settings as $key => &$value) {
                if (!empty($settings->{$key}) && $settings->{$key}) {
                    if (is_object($settings->{$key})) {
                        $value = array_merge(
                            $value,
                            json_decode(json_encode($settings->{$key}, JSON_FORCE_OBJECT), true)
                        );
                    } else {
                        $value = $settings->{$key};
                    }
                }
            }
        }
    }
926054
public function multiInsert(array $sets, $imp = true)
    {
        if (!$imp) {
            foreach ($sets as $set) {
                $this->insert($set);
            }
            return;
        }
        if (empty($sets)) {
            return;
        }
        if ($this->map) {
            foreach ($sets as &$set) {
                $set = $this->map->set($set);
            }
            unset($set);
        }
        if ($this->fake) {
            return $this->fake->multiInsert($sets);
        }
        if (isset($sets[0])) {
            $first = $sets[0];
        } else {
            $first = current($sets);
        }
        $pattern = 'INSERT INTO ?t (?cols) VALUES ?vn';
        $data = array($this->name, array_keys($first), $sets);
        $this->db->query($pattern, $data);
    }