Search in sources :

Example 6 with SQL

use of lucee.runtime.db.SQL 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)

Example 7 with SQL

use of lucee.runtime.db.SQL in project Lucee by lucee.

the class QueryArray method toDumpData.

@Override
public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) {
    DumpTable dt = (DumpTable) super.toDumpData(pageContext, maxlevel, dp);
    StringBuilder comment = new StringBuilder();
    // table.appendRow(1, new SimpleDumpData("SQL"), new SimpleDumpData(sql.toString()));
    String template = getTemplate();
    if (!StringUtil.isEmpty(template))
        comment.append("Template: ").append(template).append("\n");
    int top = dp.getMaxlevel();
    comment.append("Execution Time: ").append(Caster.toString(FormatUtil.formatNSAsMSDouble(getExecutionTime()))).append(" ms \n");
    comment.append("Record Count: ").append(Caster.toString(size()));
    if (size() > top)
        comment.append(" (showing top ").append(Caster.toString(top)).append(")");
    comment.append("\n");
    comment.append("Cached: ").append(isCached() ? "Yes\n" : "No\n");
    if (isCached()) {
        String ct = getCacheType();
        comment.append("Cache Type: ").append(ct).append("\n");
    }
    SQL sql = getSql();
    if (sql != null)
        comment.append("SQL: ").append("\n").append(StringUtil.suppressWhiteSpace(sql.toString().trim())).append("\n");
    dt.setTitle("Array (from Query)");
    if (dp.getMetainfo())
        dt.setComment(comment.toString());
    return dt;
}
Also used : DumpTable(lucee.runtime.dump.DumpTable) SQL(lucee.runtime.db.SQL)

Example 8 with SQL

use of lucee.runtime.db.SQL in project Lucee by lucee.

the class QueryStruct method toDumpData.

@Override
public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) {
    DumpTable dt = (DumpTable) super.toDumpData(pageContext, maxlevel, dp);
    StringBuilder comment = new StringBuilder();
    // table.appendRow(1, new SimpleDumpData("SQL"), new SimpleDumpData(sql.toString()));
    String template = getTemplate();
    if (!StringUtil.isEmpty(template))
        comment.append("Template: ").append(template).append("\n");
    int top = dp.getMaxlevel();
    comment.append("Execution Time: ").append(Caster.toString(FormatUtil.formatNSAsMSDouble(getExecutionTime()))).append(" ms \n");
    comment.append("Record Count: ").append(Caster.toString(size()));
    if (size() > top)
        comment.append(" (showing top ").append(Caster.toString(top)).append(")");
    comment.append("\n");
    comment.append("Cached: ").append(isCached() ? "Yes\n" : "No\n");
    if (isCached()) {
        String ct = getCacheType();
        comment.append("Cache Type: ").append(ct).append("\n");
    }
    SQL sql = getSql();
    if (sql != null)
        comment.append("SQL: ").append("\n").append(StringUtil.suppressWhiteSpace(sql.toString().trim())).append("\n");
    dt.setTitle("Struct (from Query)");
    if (dp.getMetainfo())
        dt.setComment(comment.toString());
    return dt;
}
Also used : DumpTable(lucee.runtime.dump.DumpTable) SQL(lucee.runtime.db.SQL)

Aggregations

SQL (lucee.runtime.db.SQL)8 PageException (lucee.runtime.exp.PageException)4 QueryImpl (lucee.runtime.type.QueryImpl)4 Log (lucee.commons.io.log.Log)3 ConfigImpl (lucee.runtime.config.ConfigImpl)3 SQLImpl (lucee.runtime.db.SQLImpl)3 DumpTable (lucee.runtime.dump.DumpTable)3 Query (lucee.runtime.type.Query)3 Struct (lucee.runtime.type.Struct)3 StructImpl (lucee.runtime.type.StructImpl)3 SQLException (java.sql.SQLException)2 Date (java.util.Date)2 DataSource (lucee.runtime.db.DataSource)2 DataSourceManager (lucee.runtime.db.DataSourceManager)2 DatasourceConnection (lucee.runtime.db.DatasourceConnection)2 SQLItemImpl (lucee.runtime.db.SQLItemImpl)2 DatabaseException (lucee.runtime.exp.DatabaseException)2 Key (lucee.runtime.type.Collection.Key)2 SimpleQuery (lucee.runtime.type.query.SimpleQuery)2 Clob (java.sql.Clob)1