Method used to append to the from part of an SQL statement.

@param _select   SQL select wrapper
@throws EFapsException on error
766604
public void append2SQLFrom(final SQLSelect _select)
        throws EFapsException
    {
        // for attributes it must be evaluated if the attribute is inside a child table
        if (this.valueSelect != null && "attribute".equals(this.valueSelect.getValueType())) {
            final Type type;
            if (this.selectParts.size() > 0) {
                type = this.selectParts.get(this.selectParts.size() - 1).getType();
            } else {
                type = this.query.getMainType();
            }
            Attribute attr = this.valueSelect.getAttribute();
            if (attr == null) {
                attr = type.getAttribute(((AttributeValueSelect) this.valueSelect).getAttrName());
            }
            // if the attr is still null that means that the type does not have this attribute, so last
            // chance to find the attribute is to search in the child types
            if (attr == null) {
                for (final Type childType : type.getChildTypes()) {
                    attr = childType.getAttribute(((AttributeValueSelect) this.valueSelect).getAttrName());
                    if (attr != null) {
                        ((AttributeValueSelect) this.valueSelect).setAttribute(attr);
                        break;
                    }
                }
            }
            if (attr != null && attr.getTable() != null && !attr.getTable().equals(type.getMainTable())) {
                final ChildTableSelectPart childtable = new ChildTableSelectPart(type, attr.getTable());
                this.selectParts.add(childtable);
            }
        }
        for (final ISelectPart sel : this.selectParts) {
            this.tableIndex = sel.join(this, _select, this.tableIndex);
        }
    }
1033398
@Override
    public void executeWithoutTrigger()
        throws EFapsException
    {
        final Context context = Context.getThreadContext();
        ConnectionResource con = null;
        try {

            con = context.getConnectionResource();

            final SQLTable mainTable = getType().getMainTable();

            final long id = executeOneStatement(con, mainTable, getTable2values().get(mainTable), 0);

            setInstance(Instance.get(getInstance().getType(), id));

            getInstance().setExchangeId(this.exchangeId);
            getInstance().setExchangeSystemId(this.exchangeSystemId);

            GeneralInstance.insert(getInstance(), con);

            for (final Entry<SQLTable, List<Value>> entry :  getTable2values().entrySet()) {
                final SQLTable table = entry.getKey();
                if (!table.equals(mainTable) && !table.isReadOnly()) {
                    executeOneStatement(con, table, entry.getValue(), id);
                }
            }
            Queue.registerUpdate(getInstance());
        } finally {

        }
    }
276067
public boolean isList4Select(final String _selectStmt)
        throws EFapsException
    {
        final OneSelect oneselect = this.selectStmt2OneSelect.get(_selectStmt);
        return oneselect == null ? false : oneselect.isMultiple();
    }
45623
private void addValuesToSelection(Selection results, byte key) {
        if (key != DEFAULT_RETURN_VALUE) {
            int i = 0;
            for (byte next : values) {
                if (key == next) {
                    results.add(i);
                }
                i++;
            }
        }
    }
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);
    }
569774
private void executeInserts() throws EFapsException
    {
        ConnectionResource con = null;
        try {
            final Insert insert = (Insert) runnable;
            con = Context.getThreadContext().getConnectionResource();
            long id = 0;
            for (final Entry<SQLTable, AbstractSQLInsertUpdate<?>> entry : updatemap.entrySet()) {
                if (id != 0) {
                    entry.getValue().column(entry.getKey().getSqlColId(), id);
                }
                if (entry.getKey().getSqlColType() != null) {
                    entry.getValue().column(entry.getKey().getSqlColType(), insert.getType().getId());
                }
                final Long created = ((SQLInsert) entry.getValue()).execute(con);
                if (created != null) {
                    id = created;
                    insert.evaluateInstance(created);
                }
            }
        } catch (final SQLException e) {
            throw new EFapsException(SQLRunner.class, "executeOneCompleteStmt", e);
        }
    }
112023
protected List<Boolean> access(final Select _select)
        throws EFapsException
    {
        List<Boolean> ret = new ArrayList<>();
        // remove the IAuxillary to determine the size
        int size = _select.getElements().size();
        while (_select.getElements().get(size - 1) instanceof IAuxillary) {
            size--;
        }
        if (size == 1) {
            ret.add(this.access.hasAccess(inst()));
        } else {
            int idx = 0;
            boolean accessTemp = true;
            while (idx < size && accessTemp) {
                final AbstractElement<?> element = _select.getElements().get(idx);
                idx++;
                final Select instSelect = this.selection.getInstSelects().get(element.getPath());
                if (element instanceof AttributeSetElement) {
                    idx = size;
                    if (instSelect.getCurrent() != null && instSelect.getCurrent() instanceof Collection) {
                        ret = Collections.nCopies(((Collection<?>) instSelect.getCurrent()).size(), true);
                    }
                } else {
                    if (instSelect == null) {
                        LOG.error("Could not retrieve Instance Select for Path {}", element.getPath());
                    }
                    final Object obj = instSelect.getCurrent();
                    if (obj instanceof Instance) {
                        accessTemp = this.access.hasAccess((Instance) obj);
                        ret.clear();
                        ret.add(accessTemp);
                    } else if (obj instanceof List) {
                        if (ret.isEmpty()) {
                            ret = ((List<?>) obj).stream()
                                            .map(ele -> this.access.hasAccess((Instance) ele))
                                            .collect(Collectors.toList());
                        } else {
                            final Iterator<Boolean> iter = ret.iterator();
                            ret = ((List<?>) obj).stream()
                                            .map(ele -> iter.next() && this.access.hasAccess((Instance) ele))
                                            .collect(Collectors.toList());
                        }
                        accessTemp = ret.contains(true);
                    }
                }
            }
        }
        return ret;
    }
165791
private void preparePrint(final AbstractPrint _print) throws EFapsException {
        for (final Select select : _print.getSelection().getAllSelects()) {
            for (final AbstractElement<?> element : select.getElements()) {
                if (element instanceof AbstractDataElement) {
                    ((AbstractDataElement<?>) element).append2SQLSelect(sqlSelect);
                }
            }
        }
        if (sqlSelect.getColumns().size() > 0) {
            for (final Select select : _print.getSelection().getAllSelects()) {
                for (final AbstractElement<?> element : select.getElements()) {
                    if (element instanceof AbstractDataElement) {
                        ((AbstractDataElement<?>) element).append2SQLWhere(sqlSelect.getWhere());
                    }
                }
            }
            if (_print instanceof ObjectPrint) {
                addWhere4ObjectPrint((ObjectPrint) _print);
            } else if (_print instanceof ListPrint) {
                addWhere4ListPrint((ListPrint) _print);
            } else {
                addTypeCriteria((QueryPrint) _print);
                addWhere4QueryPrint((QueryPrint) _print);
            }
            addCompanyCriteria(_print);
        }
    }
1094228
private void get(final StringBuilder sql) {
        sql.append("SELECT * FROM ").append(getName()).append(" WHERE ").append(JdbcRepositories.getDefaultKeyName()).append(" = ?");
    }
1277896
protected void appendBaseTable(final SQLSelect _sqlSelect, final SQLTable _sqlTable)
    {
        if (_sqlSelect.getFromTables().isEmpty()) {
            final TableIdx tableidx = _sqlSelect.getIndexer().getTableIdx(_sqlTable.getSqlTable());
            if (tableidx.isCreated()) {
                _sqlSelect.from(tableidx.getTable(), tableidx.getIdx());
            }
        }
    }
948023
public void addChildValueSelect(final AbstractValueSelect _valueSelect)
        throws EFapsException
    {
        if (this.child == null) {
            this.child = _valueSelect;
            _valueSelect.setParentValueSelect(this);
        } else {
            this.child.addChildValueSelect(_valueSelect);
        }
    }
622823
public void perform(final Appender ap) 
        throws SQLException, UnsupportedEncodingException {

        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;

        try {
            con = JDBC.connect(this.jdbcDriver, this.jdbcUrl, 
                               this.user, this.pass);

            stmt = con.createStatement();
            rs = stmt.executeQuery(this.sql);

            appendRows(new ResultIterator(rs), ap, 
                       this.charset, this.formatting, this.cols);

        } finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (Exception e) {
                    e.printStackTrace();
                } // end of catch
            } // end of if

            if (stmt != null) {
                try {
                    stmt.close();
                } catch (Exception e) {
                    e.printStackTrace();
                } // end of catch
            } // end of if

            if (con != null) {
                try {
                    con.close();
                } catch (Exception e) {
                    e.printStackTrace();
                } // end of catch
            } // end of if
        } // end of finally
    }
232145
public function selectPdo($select, $param = null)
    {
        $statement = $this->getAdapter()->query($select, ADT::QUERY_MODE_PREPARE);
        $result = $statement->execute($param);

        $resultSet = clone $this->resultSetPrototype;

        return $resultSet->initialize($result);
    }
867848
private void appendClazzColumnForSelect(StringBuffer buf)
    {
        ClassDescriptor cld = getSearchClassDescriptor();
        ClassDescriptor[] clds = getMultiJoinedClassDescriptors(cld);

        if (clds.length == 0)
        {
            return;
        }
        
        buf.append(",CASE");

        for (int i = clds.length; i > 0; i--)
        {
            buf.append(" WHEN ");

            ClassDescriptor subCld = clds[i - 1];
            FieldDescriptor[] fieldDescriptors = subCld.getPkFields();

            TableAlias alias = getTableAliasForClassDescriptor(subCld);
            for (int j = 0; j < fieldDescriptors.length; j++)
            {
                FieldDescriptor field = fieldDescriptors[j];
                if (j > 0)
                {
                    buf.append(" AND ");
                }
                appendColumn(alias, field, buf);
                buf.append(" IS NOT NULL");
            }
            buf.append(" THEN '").append(subCld.getClassNameOfObject()).append("'");
        }
        buf.append(" ELSE '").append(cld.getClassNameOfObject()).append("'");
        buf.append(" END AS " + SqlHelper.OJB_CLASS_COLUMN);
    }
448442
def visit_select(self, select, asfrom=False, parens=True,
                     fromhints=None,
                     compound_index=0,
                     nested_join_translation=False,
                     select_wraps_for=None,
                     **kwargs):
        jsn = {'command': 'advanced/search', 'type': 'select'}
        needs_nested_translation = \
            select.use_labels and \
            not nested_join_translation and \
            not self.stack and \
            not self.dialect.supports_right_nested_joins

        if needs_nested_translation:
            transformed_select = self._transform_select_for_nested_joins(
                select)
            text = self.visit_select(
                transformed_select, asfrom=asfrom, parens=parens,
                fromhints=fromhints,
                compound_index=compound_index,
                nested_join_translation=True, **kwargs
            )

        toplevel = not self.stack
        entry = self._default_stack_entry if toplevel else self.stack[-1]

        populate_result_map = toplevel or \
                              (
                                  compound_index == 0 and entry.get(
                                      'need_result_map_for_compound', False)
                              ) or entry.get('need_result_map_for_nested',
                                             False)

        # this was first proposed as part of #3372; however, it is not
        # reached in current tests and could possibly be an assertion
        # instead.
        if not populate_result_map and 'add_to_result_map' in kwargs:
            del kwargs['add_to_result_map']

        if needs_nested_translation:
            if populate_result_map:
                self._transform_result_map_for_nested_joins(
                    select, transformed_select)
            return jsn

        froms = self._setup_select_stack(select, entry, asfrom)

        column_clause_args = kwargs.copy()
        column_clause_args.update({
            'within_label_clause': False,
            'within_columns_clause': False
        })

        if select._hints:
            hint_text, byfrom = self._setup_select_hints(select)
            if hint_text:
                text += hint_text + " "
        else:
            byfrom = None


        
        if select._distinct:
            jsn['distinct'] = True

        # the actual list of columns to print in the SELECT column list.
        inner_columns = [
            c for c in [
                self._label_select_column(
                    select,
                    column,
                    populate_result_map, asfrom,
                    column_clause_args,
                    name=name)
                for name, column in select._columns_plus_names
                ]
            if c is not None
            ]

        if populate_result_map and select_wraps_for is not None:
            # if this select is a compiler-generated wrapper,
            # rewrite the targeted columns in the result map
            wrapped_inner_columns = set(select_wraps_for.inner_columns)
            translate = dict(
                (outer, inner.pop()) for outer, inner in [
                    (
                        outer,
                        outer.proxy_set.intersection(wrapped_inner_columns))
                    for outer in select.inner_columns
                    ] if inner
            )
            self._result_columns = [
                (key, name, tuple(translate.get(o, o) for o in obj), type_)
                for key, name, obj, type_ in self._result_columns
                ]

        jsn = self._compose_select_body(
            jsn, select, inner_columns, froms, byfrom, kwargs)

        if select._statement_hints:
            per_dialect = [
                ht for (dialect_name, ht)
                in select._statement_hints
                if dialect_name in ('*', self.dialect.name)
                ]
            if per_dialect:
                text += " " + self.get_statement_hint_text(per_dialect)

        if self.ctes and self._is_toplevel_select(select):
            text = self._render_cte_clause() + text

        if select._suffixes:
            text += " " + self._generate_prefixes(
                select, select._suffixes, **kwargs)

        self.stack.pop(-1)

        if asfrom and parens:
            return jsn  # "(" + text + ")"
        else:
            return jsn
218021
private void updateFalseLoginDB(final int _tries)
        throws EFapsException
    {
        Connection con = null;
        try {
            con = Context.getConnection();

            Statement stmt = null;
            final StringBuilder cmd = new StringBuilder();
            try {

                cmd.append("update T_USERPERSON ").append("set LOGINTRY=").append(
                                Context.getDbType().getCurrentTimeStamp()).append(", LOGINTRIES=").append(_tries)
                                .append(" where ID=").append(getId());
                stmt = con.createStatement();
                final int rows = stmt.executeUpdate(cmd.toString());
                if (rows == 0) {
                    Person.LOG.error("could not execute '" + cmd.toString()
                                    + "' to update last login information for person '" + toString() + "'");
                    throw new EFapsException(getClass(), "updateLastLogin.NotUpdated", cmd.toString(), getName());
                }
            } catch (final SQLException e) {
                Person.LOG.error("could not execute '" + cmd.toString()
                                + "' to update last login information for person '" + toString() + "'", e);
                throw new EFapsException(getClass(), "updateLastLogin.SQLException", e, cmd.toString(), getName());
            } finally {
                try {
                    if (stmt != null) {
                        stmt.close();
                    }
                } catch (final SQLException e) {
                    throw new EFapsException(getClass(), "updateLastLogin.SQLException", e, cmd.toString(), getName());
                }
            }
            con.commit();
            con.close();
        } catch (final SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
662967
public AbstractPrintQuery addMsgPhrase(final SelectBuilder _selectBldr,
                                           final CIMsgPhrase... _ciMsgPhrases)
        throws EFapsException
    {
        final Set<MsgPhrase> msgPhrases = new HashSet<>();
        for (final CIMsgPhrase ciMsgPhrase : _ciMsgPhrases) {
            msgPhrases.add(ciMsgPhrase.getMsgPhrase());
        }
        return addMsgPhrase(_selectBldr, msgPhrases.toArray(new MsgPhrase[msgPhrases.size()]));
    }