Checks whether the Criteria needs to use column aliasing
This is implemented in a service class rather than in Criteria itself
in order to avoid doing the tests when it's not necessary (e.g. for SELECTs)
424069
public static function needsSelectAliases(Criteria $criteria)
    {
        $columnNames = array();
        foreach ($criteria->getSelectColumns() as $fullyQualifiedColumnName) {
            if ($pos = strrpos($fullyQualifiedColumnName, '.')) {
                $columnName = substr($fullyQualifiedColumnName, $pos);
                if (isset($columnNames[$columnName])) {
                    // more than one column with the same name, so aliasing is required
                    return true;
                }
                $columnNames[$columnName] = true;
            }
        }

        return false;
    }
556151
function requireValidColumns (model, extraColumns) {
    assert.equal(typeof extraColumns, 'object', 'columns must be object')
    // clone arg since it may be modified
    extraColumns = _.cloneDeep(extraColumns)
    // validate each column definition
    _.each(extraColumns, (spec, name) => {
        // check if name is a default column name
        var defaultColumnName = model.columnName(name)
        // spec is for default column
        if (defaultColumnName) {
            // if spec is false then remove default column
            if (spec === false) {
                // delete all entries for default column
                delete model.columns[defaultColumnName]
                delete model.defaultColumnsInverse[model.defaultColumns[defaultColumnName]]
                delete model.defaultColumns[defaultColumnName]
                // delete original entry in extra columns
                delete extraColumns[name]
            }
            // otherwise override default values with spec
            else {
                // merge spec over default
                _.merge(model.columns[defaultColumnName], spec)
                // delete original entry in extra columns
                delete extraColumns[name]
            }
        }
        // spec is for extra column
        else {
            // get validated spec
            extraColumns[name] = requireValidColumn(name, spec)
        }
    })

    // return validated columns
    return extraColumns
}
228407
function initArgs () {
    // set default for where if not set
    this.args.where = requireValidOptionalObject(this.args.where)
    // do not allow arguments that should only be used internally
    this.assert(!defined(this.args.accessId), 'accessId not allowed')
    this.assert(!defined(this.args.accessIdName), 'accessIdName not allowed')
    // custom select columns are deprecated
    this.assert(!defined(this.args.select), 'select is deprecated')
    // if view is array with false value set to false
    if (Array.isArray(this.args.view) && this.args.view.length === 1 && this.args.view[0] === false) {
        this.args.view = false
    }
    // one is an alias for limit:1
    if (this.args.one) {
        // one cannot be set with limit
        this.assert(!defined(this.args.limit), 'one cannot be used with limit')
        // set limit:1
        this.args.limit = 1
        // delete one
        delete this.args.one
    }
    // normalize where args
    _.each(this.args.where, (options, property) => {
        // if there is only one operator then see if query can be simplified
        if (typeof options === 'object' && options && _.keys(options).length === 1) {
            // if operator is eq then replace object with direct query
            if (defined(options.eq)) {
                this.args.where[property] = options.eq
            }
            // if operator is in then replace object with direct query
            if (defined(options.in)) {
                this.args.where[property] = options.in
            }            
        }
    })
    // if model has d(eleted) column then default to isDeleted:false
    if (defined(this.model.columns.d) && !defined(this.args.where.isDeleted)) {
        this.args.where.isDeleted = false
    }
}
843339
def requiredUnless(col_name, arg, dm, df, *args):
    
    # if column name is present, no need to check if it is required
    if col_name in df.columns:
        return None
    arg_list = arg.split(",")
    arg_list = [argument.strip('"') for argument in arg_list]
    msg = ""
    for a in arg_list:
        # ignore validations that reference a different table
        if "." in a:
            continue
        if a not in df.columns:
            msg += "{} column is required unless {} is present.  ".format(col_name, a)
    if msg:
        return msg
    else:
        return None
    return None
920337
public function checkCriteriaValidity()
    {
        foreach ($this->lookup_queries as $col) {
            if ($col->required == "yes") {
                //ReporticoApp::handleError( "Mandatory" );
                if (!$this->lookup_queries[$col->query_name]->column_value) {
                    if (true || ReporticoUtility::getRequestItem("new_reportico_window", false)) {
                        $this->http_response_code = 500;
                        $this->return_to_caller = true;
                        ReporticoApp::handleError(ReporticoLang::templateXlate("REQUIRED_CRITERIA") . " - " . ReporticoLang::translate($this->lookup_queries[$col->query_name]->deriveAttribute("column_title", "")));
                        //echo '<div class="reportico-error-box">'.ReporticoLang::templateXlate("REQUIRED_CRITERIA")." - ".ReporticoLang::translate($this->lookup_queries[$col->query_name]->deriveAttribute("column_title", ""))."</div>";
                        return;
                    } else {
                        ReporticoApp::handleError(ReporticoLang::templateXlate("REQUIRED_CRITERIA") . " - " . ReporticoLang::translate($this->lookup_queries[$col->query_name]->deriveAttribute("column_title", ""))
                            , E_USER_ERROR);
                    }

                }
            }
        }
    }
413280
public boolean isCaseSensitive(int column) throws SQLException
    {
        sourceResultSet.checkColumnBounds(column);
        VoltType type = sourceResultSet.table.getColumnType(column - 1);
        return type.isCaseSensitive();
    }
414838
def method_missing(m, *args, &block)
      column_name = m.to_s.gsub(/\=$/, '')
      raise ExtendModelAt::InvalidColumn, "#{column_name} not exist" if @static == true and not (@columns.try(:keys).try(:include?, column_name.to_sym) )
      # If the method don't finish with "=" is fore read
      if m !~ /\=$/
        self[m.to_s]
      # but if finish with "=" is for wirte
      else
        self[column_name.to_s] = args.first
      end
    end
471392
function (identifier) {
            return isString(identifier) ? this.__hashIdentifierToName(this.stringToIdentifier(identifier)) :
                isInstanceOf(identifier, Identifier) ? identifier.value :
                    isInstanceOf(identifier, QualifiedIdentifier) ? identifier.column :
                        isInstanceOf(identifier, AliasedExpression) ? identifier.alias : identifier;
        }
965500
def using_single_table_inheritance?(klass, record)
      inheritance_column = klass.inheritance_column
      record[inheritance_column].present? && record.has_attribute?(inheritance_column)
    end
181362
def columns
      # we want to delay initializing to the @core.columns set for as long as possible. Too soon and .search_sql will not be available to .searchable?
      unless defined? @columns
        self.columns = @core.columns.collect { |c| c.name if @core.columns._inheritable.include?(c.name) && c.searchable? && c.association.nil? && c.text? }.compact
      end
      @columns
    end
508671
function checkSelectOnlyIds () {
    // default to false
    this.isSelectOnlyIds = false
    // false if doing select by id
    if (this.isSelectById) {
        return
    }
    // false if selecting all and not using cache
    if (this.args.all && (!this.model.cache || this.args.cache === false)) {
        return
    }
    // false if selecting a single record
    if (this.args.limit === 1) {
        return
    }
    // false if selecting custom columns
    if (defined(this.args.select)) {
        return
    }
    // false if fetching isCurrent
    if (this.args.isCurrent) {
        return
    }
    // set to true if all negative tests passed
    this.isSelectOnlyIds = true
}
775640
def available_columns
      column_options.reject{|column| viable_report_columns.map(&:column_name).include? column.name.to_s}
    end
371010
def can_perform_case_insensitive_comparison_for?(column)
      @case_insensitive_cache ||= {}
      @case_insensitive_cache[column.sql_type] ||= begin
        sql = <<~SQL
          SELECT exists(
            SELECT * FROM pg_proc
            WHERE proname = 'lower'
              AND proargtypes = ARRAY[#{quote column.sql_type}::regtype]::oidvector
          ) OR exists(
            SELECT * FROM pg_proc
            INNER JOIN pg_cast
              ON ARRAY[casttarget]::oidvector = proargtypes
            WHERE proname = 'lower'
              AND castsource = #{quote column.sql_type}::regtype
          )
        SQL
        select_value(sql, 'SCHEMA')
      end
    end
507362
private List<Table> findAllUsedTablesInFrom() {
        List<Table> allTables = new ArrayList<Table>();
        Map<Table, List<JoinCriteria>> sourceMap = new HashMap<Table, List<JoinCriteria>>();
        Map<Table, List<JoinCriteria>> destMap = new HashMap<Table, List<JoinCriteria>>();
        
        // see what tables are used in outer joins        
        for (Object criteria : criterias) {
            try {
                JoinCriteria joinCriteria = (JoinCriteria) criteria;
                Table sourceTable = joinCriteria.getSource().getTable();
                Table destTable = joinCriteria.getDestination().getTable();
                List<JoinCriteria> sourceList = sourceMap.get(sourceTable);
                List<JoinCriteria> destList = sourceMap.get(destTable);
                if (sourceList == null) {
                	sourceList = new ArrayList<JoinCriteria>();
                	sourceMap.put(sourceTable, sourceList);
                }
                sourceList.add(joinCriteria);        
                if (destList == null) {
                	destList = new ArrayList<JoinCriteria>();
                	destMap.put(destTable, destList);
                }
                destList.add(joinCriteria);        
            } catch (ClassCastException ex) {
                // not a JoinCriteria
            }
        }    
        
        // add tables from column selection
        for (Column column : columns) {
            Table table = column.getTable();
            if (table != null) {
                table.setDialect(dialect);
            }
            if (canAddTableToFromClause(table, destMap, allTables)) {
            	table.setJoins(sourceMap.get(table));
        		allTables.add(table);
        	}    
        }        
        
        // add tables from criterias 
        // it is possible that a table is used only in joins without any column selection from it
        for (Object criteria : criterias) {
            try {            	
                JoinCriteria joinCriteria = (JoinCriteria) criteria;
                Table sourceTable = joinCriteria.getSource().getTable();
                Table destTable = joinCriteria.getDestination().getTable();
                if (canAddTableToFromClause(sourceTable, destMap, allTables)) {
                	sourceTable.setJoins(sourceMap.get(sourceTable));
            		allTables.add(sourceTable);
            	}                
                if (canAddTableToFromClause(destTable, destMap, allTables)) {
                	destTable.setJoins(destMap.get(destTable));
                    allTables.add(destTable);
                }                                 
            } catch (ClassCastException ex) {
                // not a JoinCriteria
            }
        }

        // add tables used by order columns
        for (Order order : orders) {
            Table table = order.getColumn().getTable();
            if (table != null) {
                table.setDialect(dialect);
            }
            if (canAddTableToFromClause(table, destMap, allTables)) {
                allTables.add(table);
            }
        }

        return allTables;
    }
1281225
public void validate(Columns columns) {
        for (Mapper mapper : mappers.values()) {
            mapper.validate(columns);
        }
    }
756590
private boolean eligibleToFetch(List<String> columnsToSelect, String columnName)
    {
        return (columnsToSelect != null && !columnsToSelect.isEmpty() && columnsToSelect.contains(columnName))
                || (columnsToSelect == null || columnsToSelect.isEmpty());
    }
324319
def add_order_by_for_association_limiting!(sql, options)
      return sql if options[:order].blank?

      order_columns = extract_order_columns(options[:order]) do |columns|
        columns.map! { |s| $1 if s =~ / (.*)/ }; columns
      end
      order = order_columns.map { |s, i| "alias_#{i}__ #{s}" } # @see {#distinct}

      sql << "ORDER BY #{order.join(', ')}"
    end