Search in sources :

Example 51 with Query

use of lucee.runtime.type.Query in project Lucee by lucee.

the class Ldap method _doStartTag.

private int _doStartTag() throws NamingException, PageException, IOException, ClassException {
    // LDAPClient client=new LDAPClient(server,port,secureLevel,returnAsBinary,username,password,referral);
    LDAPClient client = new LDAPClient(server, port, returnAsBinary);
    if (secureLevel != LDAPClient.SECURE_NONE)
        client.setSecureLevel(secureLevel);
    if (username != null)
        client.setCredential(username, password);
    if (referral > 0)
        client.setReferral(referral);
    if (action.equals("add")) {
        required("LDAP", action, "attributes", attributes);
        required("LDAP", action, "dn", dn);
        client.add(dn, attributes, delimiter, separator);
    } else if (action.equals("delete")) {
        required("LDAP", action, "dn", dn);
        client.delete(dn);
    } else if (action.equals("modifydn")) {
        required("LDAP", action, "attributes", attributes);
        required("LDAP", action, "dn", dn);
        client.modifydn(dn, attributes);
    } else if (action.equals("modify")) {
        required("LDAP", action, "attributes", attributes);
        required("LDAP", action, "dn", dn);
        client.modify(dn, modifyType, attributes, delimiter, separator);
    } else if (action.equals("query")) {
        required("LDAP", action, "start", start);
        required("LDAP", action, "attributes", attributes);
        required("LDAP", action, "name", name);
        Query qry = client.query(attributes, scope, startrow, maxrows, timeout, sort, sortType, sortDirection, start, separator, filter);
        pageContext.setVariable(name, qry);
    } else
        throw new ApplicationException("invalid value for attribute action [" + action + "], valid values are [add,delete,modifydn,modify,query]");
    return SKIP_BODY;
}
Also used : LDAPClient(lucee.runtime.net.ldap.LDAPClient) ApplicationException(lucee.runtime.exp.ApplicationException) Query(lucee.runtime.type.Query)

Example 52 with Query

use of lucee.runtime.type.Query in project Lucee by lucee.

the class QueryUtil method getColumnNames.

/**
 * return column names as Key from a query
 *
 * @param qry
 * @return
 */
public static Key[] getColumnNames(Query qry) {
    Query qp = Caster.toQuery(qry, null);
    if (qp != null)
        return qp.getColumnNames();
    String[] strNames = qry.getColumns();
    Key[] names = new Key[strNames.length];
    for (int i = 0; i < names.length; i++) {
        names[i] = KeyImpl.getInstance(strNames[i]);
    }
    return names;
}
Also used : Query(lucee.runtime.type.Query) SimpleQuery(lucee.runtime.type.query.SimpleQuery) Key(lucee.runtime.type.Collection.Key)

Example 53 with Query

use of lucee.runtime.type.Query in project Lucee by lucee.

the class QueryUtil method toDumpData.

public static DumpData toDumpData(Query query, PageContext pageContext, int maxlevel, DumpProperties dp) {
    maxlevel--;
    Collection.Key[] keys = CollectionUtil.keys(query);
    DumpData[] heads = new DumpData[keys.length + 1];
    // int tmp=1;
    heads[0] = new SimpleDumpData("");
    for (int i = 0; i < keys.length; i++) {
        heads[i + 1] = new SimpleDumpData(keys[i].getString());
    }
    StringBuilder comment = new StringBuilder();
    // table.appendRow(1, new SimpleDumpData("SQL"), new SimpleDumpData(sql.toString()));
    String template = query.getTemplate();
    if (!StringUtil.isEmpty(template))
        comment.append("Template: ").append(template).append("\n");
    // table.appendRow(1, new SimpleDumpData("Template"), new SimpleDumpData(template));
    // in Query dump maxlevel is used as Top
    int top = dp.getMaxlevel();
    comment.append("Execution Time: ").append(Caster.toString(FormatUtil.formatNSAsMSDouble(query.getExecutionTime()))).append(" ms \n");
    comment.append("Record Count: ").append(Caster.toString(query.getRecordcount()));
    if (query.getRecordcount() > top)
        comment.append(" (showing top ").append(Caster.toString(top)).append(")");
    comment.append("\n");
    comment.append("Cached: ").append(query.isCached() ? "Yes\n" : "No\n");
    if (query.isCached() && query instanceof Query) {
        comment.append("Cache Type: ").append(query.getCacheType()).append("\n");
    }
    comment.append("Lazy: ").append(query instanceof SimpleQuery ? "Yes\n" : "No\n");
    SQL sql = query.getSql();
    if (sql != null)
        comment.append("SQL: ").append("\n").append(StringUtil.suppressWhiteSpace(sql.toString().trim())).append("\n");
    // table.appendRow(1, new SimpleDumpData("Execution Time (ms)"), new SimpleDumpData(exeTime));
    // table.appendRow(1, new SimpleDumpData("recordcount"), new SimpleDumpData(getRecordcount()));
    // table.appendRow(1, new SimpleDumpData("cached"), new SimpleDumpData(isCached()?"Yes":"No"));
    DumpTable recs = new DumpTable("query", "#cc99cc", "#ffccff", "#000000");
    recs.setTitle("Query");
    if (dp.getMetainfo())
        recs.setComment(comment.toString());
    recs.appendRow(new DumpRow(-1, heads));
    // body
    DumpData[] items;
    int recordcount = query.getRecordcount();
    int columncount = query.getColumnNames().length;
    for (int i = 0; i < recordcount; i++) {
        items = new DumpData[columncount + 1];
        items[0] = new SimpleDumpData(i + 1);
        for (int y = 0; y < keys.length; y++) {
            try {
                Object o = query.getAt(keys[y], i + 1);
                if (o instanceof String)
                    items[y + 1] = new SimpleDumpData(o.toString());
                else if (o instanceof Number)
                    items[y + 1] = new SimpleDumpData(Caster.toString(((Number) o)));
                else if (o instanceof Boolean)
                    items[y + 1] = new SimpleDumpData(((Boolean) o).booleanValue());
                else if (o instanceof Date)
                    items[y + 1] = new SimpleDumpData(Caster.toString(o));
                else if (o instanceof Clob)
                    items[y + 1] = new SimpleDumpData(Caster.toString(o));
                else
                    items[y + 1] = DumpUtil.toDumpData(o, pageContext, maxlevel, dp);
            } catch (PageException e) {
                items[y + 1] = new SimpleDumpData("[empty]");
            }
        }
        recs.appendRow(new DumpRow(1, items));
        if (i == top - 1)
            break;
    }
    if (!dp.getMetainfo())
        return recs;
    // table.appendRow(1, new SimpleDumpData("result"), recs);
    return recs;
}
Also used : PageException(lucee.runtime.exp.PageException) Query(lucee.runtime.type.Query) SimpleQuery(lucee.runtime.type.query.SimpleQuery) SimpleQuery(lucee.runtime.type.query.SimpleQuery) DumpRow(lucee.runtime.dump.DumpRow) DumpData(lucee.runtime.dump.DumpData) SimpleDumpData(lucee.runtime.dump.SimpleDumpData) Date(java.util.Date) SQL(lucee.runtime.db.SQL) DumpTable(lucee.runtime.dump.DumpTable) SimpleDumpData(lucee.runtime.dump.SimpleDumpData) Clob(java.sql.Clob) Key(lucee.runtime.type.Collection.Key)

Example 54 with Query

use of lucee.runtime.type.Query in project Lucee by lucee.

the class VariableReference method touch.

@Override
public Object touch(PageContext pc) throws PageException {
    Object o;
    if (coll instanceof Query) {
        o = ((Query) coll).getColumn(key, null);
        if (o != null)
            return o;
        return set(pc, new StructImpl());
    }
    o = coll.get(key, null);
    if (o != null)
        return o;
    return set(pc, new StructImpl());
}
Also used : StructImpl(lucee.runtime.type.StructImpl) Query(lucee.runtime.type.Query)

Example 55 with Query

use of lucee.runtime.type.Query in project Lucee by lucee.

the class Ansi92 method select.

@Override
public Query select(Config config, String cfid, String applicationName, DatasourceConnection dc, int type, Log log, boolean createTableIfNotExist) throws PageException {
    String strType = VariableInterpreter.scopeInt2String(type);
    Query query = null;
    SQL sqlSelect = new SQLImpl("select data from " + PREFIX + "_" + strType + "_data where cfid=? and name=? and expires > ?", new SQLItem[] { new SQLItemImpl(cfid, Types.VARCHAR), new SQLItemImpl(applicationName, Types.VARCHAR), new SQLItemImpl(now(config), Types.VARCHAR) });
    PageContext pc = ThreadLocalPageContext.get();
    try {
        query = new QueryImpl(pc, dc, sqlSelect, -1, -1, null, "query");
    } catch (DatabaseException de) {
        if (dc == null || !createTableIfNotExist)
            throw de;
        // table does not exist???
        try {
            SQL sql = createSQL(dc, DataSourceUtil.isMySQL(dc) ? "longtext" : "ntext", strType);
            ScopeContext.info(log, sql.toString());
            new QueryImpl(pc, dc, sql, -1, -1, null, "query");
        } catch (DatabaseException _de) {
            // don't like "ntext", try text
            try {
                SQL sql = createSQL(dc, "text", strType);
                ScopeContext.info(log, sql.toString());
                new QueryImpl(pc, dc, sql, -1, -1, null, "query");
            } catch (DatabaseException __de) {
                // don't like text, try "memo"
                try {
                    SQL sql = createSQL(dc, "memo", strType);
                    ScopeContext.info(log, sql.toString());
                    new QueryImpl(pc, dc, sql, -1, -1, null, "query");
                } catch (DatabaseException ___de) {
                    // don't like "memo", try clob
                    try {
                        SQL sql = createSQL(dc, "clob", strType);
                        ScopeContext.info(log, sql.toString());
                        new QueryImpl(pc, dc, sql, -1, -1, null, "query");
                    } catch (DatabaseException ____de) {
                        ___de.initCause(__de);
                        __de.initCause(_de);
                        _de.initCause(de);
                        // we could not create the table, so there seem to be an other ecception we cannot solve
                        DatabaseException exp = new DatabaseException("Unable to select from your client storage database, and was also unable to create the tables. Here's the exceptions we encountered.", null, null, dc);
                        exp.initCause(de);
                        throw exp;
                    }
                }
            }
        }
        query = new QueryImpl(pc, dc, sqlSelect, -1, -1, null, "query");
    }
    ScopeContext.info(log, sqlSelect.toString());
    return query;
}
Also used : SQLImpl(lucee.runtime.db.SQLImpl) QueryImpl(lucee.runtime.type.QueryImpl) Query(lucee.runtime.type.Query) SQLItemImpl(lucee.runtime.db.SQLItemImpl) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) PageContext(lucee.runtime.PageContext) DatabaseException(lucee.runtime.exp.DatabaseException) SQL(lucee.runtime.db.SQL)

Aggregations

Query (lucee.runtime.type.Query)82 QueryImpl (lucee.runtime.type.QueryImpl)52 Struct (lucee.runtime.type.Struct)19 Array (lucee.runtime.type.Array)16 Collection (lucee.runtime.type.Collection)14 Iterator (java.util.Iterator)13 PageException (lucee.runtime.exp.PageException)12 Map (java.util.Map)11 StructImpl (lucee.runtime.type.StructImpl)11 ApplicationException (lucee.runtime.exp.ApplicationException)10 Stopwatch (lucee.runtime.timer.Stopwatch)10 Key (lucee.runtime.type.Collection.Key)9 List (java.util.List)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 QueryColumn (lucee.runtime.type.QueryColumn)7 Enumeration (java.util.Enumeration)6 Entry (java.util.Map.Entry)6 FunctionException (lucee.runtime.exp.FunctionException)6