/*!
Forwards request to generateAddFieldSql() on the otherSchema() object.
435655
function generateAddFieldSql( $table, $field_name, $added_field, $params )
    {
        return $this->OtherSchema->generateAddFieldSql( $table, $field_name, $added_field, $params );
    }
30925
function generateTableSQLList( $tableName, $table, $params, $separateTypes )
    {
        return $this->generateTableSQL( $tableName, $table, $params, true, $separateTypes );
    }
1063260
protected void configureGeneratedIdSequence(StringBuilder sb, FieldType fieldType, List<String> statementsBefore,
			List<String> additionalArgs, List<String> queriesAfter) throws SQLException {
		throw new SQLException(
				"GeneratedIdSequence is not supported by database " + getDatabaseName() + " for field " + fieldType);
	}
794798
@Override
   public Sql[] generateSql(final InsertStatement statement, final Database database,
         final SqlGeneratorChain sqlGeneratorChain) {
      for (final Entry<String, Object> entry : statement.getColumnValues().entrySet()) {
         entry.setValue(handleColumnValue(entry.getValue(), database));
      }
      return super.generateSql(statement, database, sqlGeneratorChain);
   }
1154636
public function buildQuery($type, $field = null, $extra = null)
    {
        if($type == 'select') {
            if($field == null) {
                $field = "*";
            }
            elseif(is_array($field)) {
                foreach($field as $i => $value) {
                    $field[$i] = '`'.trim($value).'`';
                }
                $field = trim(implode(' ,', $field));
            }
            $ex = '';
            if($extra != null && is_array($extra)) {
                foreach($extra as $i => $v) {
                    if($i == 'count') {
                        $ex .= 'COUNT';
                        if($v == null) {
                            $ex .= '(*)';
                        }
                    }
                    if($i == 'field') {
                        $ex .= ' as `'.$v.'`';
                    }
                }
                $sql = "SELECT $ex FROM `".$this->getTable().'` '.$this->where;
            }
            else {
                $sql = "SELECT $field FROM `".$this->getTable().'` '.$this->where.$this->order.$this->limit;
            }
        }
        elseif($type == 'insert') {
            if(is_array($field)) {
                $keys = array_keys($field);
                if($keys[0] === 0) {
                    $keys = '';
                }
                else {
                    foreach($keys as $i => $key) {
                        $keys[$i] = ' `'.trim($key).'`';
                    }
                    $keys = implode(',', $keys);
                }
                $values = array_values($field);
                foreach($values as $i => $val) {
                    $values[$i] = is_string($val) ? "'$val'" : $val;
                }
                $values = implode(' ,', $values);
            }
            else {
                $keys = '';
                $values = trim($field);
            }
            $values = "($values)";
            $keys = ($keys !== '') ? "($keys)" : '';
            $sql = "INSERT INTO `".$this->getTable()."` $keys VALUES $values".$this->duplicateUpdate;
        }
        elseif($type == 'update') {
            if(is_array($field)) {
                foreach($field as $key => $value) {
                    $values[] = " `$key` = ".(is_string($value) ? "'$value'" : $value);
                }
                $values = implode(' ,', $values);
            }
            else {
                $values = trim($field);
            }
            $sql = "UPDATE `".$this->getTable()."` SET $values ".$this->where;
        }
        elseif($type == 'delete') {
            $sql = "DELETE FROM `".$this->getTable()."` ".$this->where;
        }
        $this->query = $sql;
        return $sql;
    }
677165
protected function generateChangeFieldSql( $tableName, $fieldName, ezcDbSchemaField $fieldDefinition )
    {
        if ( !$fieldDefinition->autoIncrement )
        {
            $this->queries[] = "ALTER TABLE \"$tableName\" MODIFY " .
                               $this->generateFieldSql( $fieldName, $fieldDefinition );
        }
        else
        {    // mark query to make autoincrement emulation when executing
            $this->queries[] = "ALTER TABLE \"$tableName\" MODIFY " .
                               $this->generateFieldSql( $fieldName, $fieldDefinition ) .
                               " AUTO_INCREMENT";
        }
    }
1231666
function () {

                if (this.factory.schema) {
                    this.schema = this.factory.schema;
                    return;
                }
                var base = this.base;

                while (base.factory.classof(Entity)) {
                    var baseSchema = base.schema;
                    for (var type in baseSchema) {
                        if (baseSchema.hasOwnProperty(type) && !this.schema.hasOwnProperty(type)) {
                            this.schema[type] = baseSchema[type];
                        }
                    }
                    base = base.base;
                }

                var schemaDefaults = {
                    required: true,
                    includeInIndex: false,
                    serverOnly: false,
                    _rewritten: true,
                    // if true, sub models get composed and not just linked
                    compose: false
                }, schemaObject;

                // add id schema
                if (this.idField && !this.schema.hasOwnProperty(this.idField)) {
                    this.schema[this.idField] = {
                        type: String,
                        required: false,
                        serverOnly: false,
                        includeInIndex: true,
                        generated: true
                    };
                }

                if (this.updatedField && !this.schema.hasOwnProperty(this.updatedField)) {
                    this.schema[this.updatedField] = {
                        type: Date,
                        required: false,
                        serverOnly: false,
                        includeInIndex: true,
                        generated: true
                    };
                }

                if (this.createdField && !this.schema.hasOwnProperty(this.createdField)) {
                    this.schema[this.createdField] = {
                        type: Date,
                        required: false,
                        includeInIndex: true,
                        serverOnly: false,
                        generated: true
                    };
                }

                // rewrite schema
                for (var key in this.schema) {
                    if (this.schema.hasOwnProperty(key)) {
                        schemaObject = this.schema[key];
                        if (_.isString(schemaObject) || schemaObject instanceof Array || schemaObject instanceof Function) {
                            schemaObject = {
                                type: schemaObject
                            };
                            this.schema[key] = schemaObject;
                        }
                        if (_.isString(schemaObject.type)) {
                            schemaObject.type = require(schemaObject.type.replace(/\./g, "/"));
                        }
                        _.defaults(schemaObject, schemaDefaults);
                        schemaObject._key = key;
                    }
                }
                this.factory.schema = this.schema;
            }
1177453
protected function _addDefaultFields()
    {
        $select = $this->clause('select');
        $this->_hasFields = true;

        /** @var \Cake\ORM\Table $repository */
        $repository = $this->getRepository();

        if (!count($select) || $this->_autoFields === true) {
            $this->_hasFields = false;
            $this->select($repository->getSchema()->columns());
            $select = $this->clause('select');
        }

        $aliased = $this->aliasFields($select, $repository->getAlias());
        $this->select($aliased, true);
    }
1204313
protected function _deriveFields()
    {
        $config = $this->getConfig();
        $table = $this->_table();

        if (method_exists($table, 'searchConfiguration')) {
            $searchManager = $table->searchConfiguration();
        } else {
            $searchManager = $table->searchManager();
        }

        $fields = [];
        $schema = $table->getSchema();
        $request = $this->_request();

        foreach ($searchManager->getFilters($config['collection']) as $filter) {
            if ($filter->getConfig('form') === false) {
                continue;
            }

            $field = $filter->name();
            $input = [
                'required' => false,
                'type' => 'text'
            ];

            if (substr($field, -3) === '_id' && $field !== '_id') {
                $input['type'] = 'select';
            }

            $filterFormConfig = $filter->getConfig('form');
            if (!empty($filterFormConfig)) {
                $input = $filterFormConfig + $input;
            }

            $input['value'] = $request->getQuery($field);

            if (empty($input['options']) && $schema->getColumnType($field) === 'boolean') {
                $input['options'] = ['No', 'Yes'];
                $input['type'] = 'select';
            }

            if (!empty($input['options'])) {
                $input['empty'] = true;
                if (empty($input['class']) && !$config['selectize']) {
                    $input['class'] = 'no-selectize';
                }

                $fields[$field] = $input;

                continue;
            }

            if (empty($input['class']) && $config['autocomplete']) {
                $input['class'] = 'autocomplete';
            }

            $urlArgs = [];

            $fieldKeys = isset($input['fields']) ? $input['fields'] : ['id' => $field, 'value' => $field];
            if (is_array($fieldKeys)) {
                foreach ($fieldKeys as $key => $val) {
                    $urlArgs[$key] = $val;
                }
            }

            unset($input['fields']);
            $url = array_merge(['action' => 'lookup', '_ext' => 'json'], $urlArgs);
            $input['data-url'] = Router::url($url);

            $fields[$field] = $input;
        }

        return $fields;
    }
1219477
function data( $schema = false, $tableNameList = false, $params = array() )
    {
        return $this->OtherSchema->data( $schema, $tableNameList, $params );
    }
563476
static function doAddProperty($arr, $schema, $key, $val, $defaults = [], $helper = NULL) {
    try {
      $val = self::processProperty($schema, $val, $defaults, $helper);

    } catch (\RoyalMail\Exception\ValidatorException $e) {
      $errors[] = $key . ': ' . $e->getMessage(); 

    } catch (\RoyalMail\Exception\RequestException $re) {
      foreach ($re->getErrors() as $k_nested => $v) $errors[$k . ':' . $k_nested] = $v;
    
    } catch (SkipException $e) { return $arr; } // Exception is notification that rules exclude this field.
     

    return self::addToArray($arr, $val, $key, @$schema['_key']);
  }
371898
protected function generateSchemaAsSql()
    {
        $prefix = ezcDbSchema::$options->tableNamePrefix;
        foreach ( $this->schema as $tableName => $tableDefinition )
        {
            $this->generateDropTableSql( $prefix . $tableName );
            $this->generateCreateTableSql( $prefix . $tableName, $tableDefinition );
        }
    }
1371669
function generateTableSQL( $tableName, $tableDef, $params, $asArray, $separateTypes = false )
    {
        $diffFriendly = isset( $params['diff_friendly'] ) ? $params['diff_friendly'] : false;
        $mysqlCompatible = isset( $params['compatible_sql'] ) ? $params['compatible_sql'] : false;

        if ( $asArray )
        {
            if ( $separateTypes )
            {
                $sqlList = array( 'tables' => array() );
            }
            else
            {
                $sqlList = array();
            }
        }

        $sql = '';
        $skip_pk = false;
        $sql_fields = array();
        $sql .= "CREATE TABLE $tableName (\n";

        $fields = $tableDef['fields'];

        foreach ( $fields as $field_name => $field_def )
        {
            $sql_fields[] = '  ' . eZMysqlSchema::generateFieldDef( $field_name, $field_def, $skip_pk_flag, $params );
            if ( $skip_pk_flag )
            {
                $skip_pk = true;
            }
        }

        // Make sure the order is as defined by 'offset'
        $indexes = $tableDef['indexes'];

        // We need to add all keys in table definition
        foreach ( $indexes as $index_name => $index_def )
        {
            $sql_fields[] = ( $diffFriendly ? '' : '  ' ) . eZMysqlSchema::generateAddIndexSql( $tableName, $index_name, $index_def, $params, true );
        }
        $sql .= join( ",\n", $sql_fields );
        $sql .= "\n)";

        // Add some extra table options if they are required
        $extraOptions = array();
        if ( isset( $params['table_type'] ) and $params['table_type'] )
        {
            $typeName = $this->tableStorageTypeName( $params['table_type'] );
            if ( $typeName )
            {
                $extraOptions[] = "ENGINE=" . $typeName;
            }
        }
        if ( isset( $params['table_charset'] ) and $params['table_charset'] )
        {
            $charsetName = $this->tableCharsetName( $params['table_charset'] );
            if ( $charsetName )
            {
                $extraOptions[] = "DEFAULT CHARACTER SET " . $charsetName;
            }
        }
        if ( isset( $tableDef['options'] ) )
        {
            foreach( $tableDef['options'] as $optionType => $optionValue )
            {
                $optionText = $this->generateTableOption( $tableName, $tableDef, $optionType, $optionValue, $params );
                if ( $optionText )
                    $extraOptions[] = $optionText;
            }
        }

        if ( count( $extraOptions ) > 0 )
        {
            $sql .= " " . implode( $diffFriendly ? "\n" : " ", $extraOptions );
        }

        if ( $asArray )
        {
            if ( $separateTypes )
            {
                $sqlList['tables'][] = $sql;
            }
            else
            {
                $sqlList[] = $sql;
            }
        }
        else
        {
            $sql .= ";\n";

            if ( $mysqlCompatible )
            {
                $sql .= "\n\n\n";
            }
        }

        return $asArray ? $sqlList : $sql;
    }
622212
protected function appendExtraFieldsToQuery()
    {
        $finalized = [];

        foreach ($this->extraFields as $field => $spec) {
            $obj = Injector::inst()->create($spec);

            if ($obj instanceof DBComposite) {
                $this->_compositeExtraFields[$field] = [];

                // append the composite field names to the select
                foreach ($obj->compositeDatabaseFields() as $subField => $subSpec) {
                    $col = $field . $subField;
                    $finalized[] = $col;

                    // cache
                    $this->_compositeExtraFields[$field][] = $subField;
                }
            } else {
                $finalized[] = $field;
            }
        }

        $this->dataQuery->addSelectFromTable($this->joinTable, $finalized);
    }
39956
function sendSuccessAnswer(table, res, id, field) {
    if(typeof field === "undefined") {
        if(id === 0) {
            //Just assume that everything went okay. It looks like a non numeric primary key.
            res.send({
                result: 'success',
                table: table
            });
            return;
        } else {
            field = "id";
        }
    }
    lastQry = connection.query('SELECT * FROM ?? WHERE ?? = ?', [table, field, id] , function (err, rows) {
        if (err) {
            sendError(res, err.code)
        } else {
            res.send({
                result: 'success',
                json: rows,
                table: table
            });
        }
    });
}
231338
public static function updateTable($postTypeSlug, $fields, $hasTags = false, $hasCategories = false)
    {
        self::$customFieldsArray = [];

        Schema::table(
            $postTypeSlug, function ($table) use ($fields) {
                $post = new Post();
                $usedSlugs = [];
                $usedSlugs = array_merge($usedSlugs, $post->fillable);

                foreach($fields as $field){
                    // generate unique slugs for every field
                    if(!isset($field['slug']) || $field['slug'] == "") {
                        $slug = self::generateSlug($field['name'], $usedSlugs);
                    }else{
                        $slug = self::generateSlug($field['slug'], $usedSlugs);
                    }
                    $usedSlugs[] = $slug;

                    $field['slug'] = $slug;

                    self::createDatabaseFields($table, $field, $slug, false);

                    // unset the canBeRemoved from array
                    if(isset($field['canBeRemoved']) && $field['canBeRemoved'] == true) {
                        unset($field['canBeRemoved']);
                    }

                    array_push(self::$customFieldsArray, $field);
                }
            }
        );

        if($hasCategories) {
            self::createCategoryRelationsTable($postTypeSlug);
        }

        if($hasTags) {
            self::createTagRelationsTable($postTypeSlug);
        }

        return self::$customFieldsArray;
    }
1271657
def forwards(self, orm):
        ""
        orm['avocado.DataField'].objects.get_or_create(
            app_name='variants',
            model_name='variantphenotype',
            field_name='hgmd_id',
            defaults={
                'name': 'HGMD',
                'published': True
            })